Error forming pointer to reference type

I'm getting some errors when trying to use -> in an iterator type. When I dig in the library defining the iterator, it seems to me that everyhing is allright and that there is no reason for the err...

I’m getting some errors when trying to use -> in an iterator type. When I dig in the library defining the iterator, it seems to me that everyhing is allright and that there is no reason for the error. Here is the code, part of boost::multi_array:

template <class T>
struct operator_arrow_proxy
{
  operator_arrow_proxy(T const& px) : value_(px) {}
  T* operator->() const { return &value_; }
  // This function is needed for MWCW and BCC, which won't call operator->
  // again automatically per 13.3.1.2 para 8
  operator T*() const { return &value_; }
  mutable T value_;
};

which is instantiated with const std::pair<double, unsigned int>&; then the compiler complains about «forming pointer to reference type ‘const std::pair<double, unsigned int>&’«.Those are internal, library substantiations. For the record, here is what I have in my code:

typedef uint32_t object_indentifier_t;
typedef std::pair< double, object_identifier_t > object_tab_t;
typedef boost::multi_array< object_tab_t, 2 > index_t;

and here is the usage that provokes the trouble:

object_identifier const& center; // Actually a parameter
index_t::const_subarray<1>::type::const_iterator pos_iterator_left = std::lower_bound( ix[i].begin(), ix[i].end(), sk[i], comparer ); 
assert( pos_iterator_left -> second == center ); // <-- Error steams from here

Here’s more error context:

/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp: In instantiation of 'struct boost::detail::multi_array::operator_arrow_proxy<const std::pair<double, unsigned int>&>':
csrc/lsh_cpp/lsh.cpp|125 col 13| required from here
/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|40 col 10| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
/opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|43 col 7| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
 csrc/lsh_cpp/lsh.cpp: In member function 'lsh_cpp::neighbour_iterator_t lsh_cpp::lsh_t::pimpl_t::query(const object_identifier_t&) const':
csrc/lsh_cpp/lsh.cpp|125 col 13| error: result of 'operator->()' yields non-pointer result

NOTE: This class is part of boost::multi_array, (I already wrote that), and I’m not instantiating it directly. I wrote above my instantiation. The class is instantiated by boost::multi_array this way:

 operator_arrow_proxy<reference>
 operator->() const
 {
     return operator_arrow_proxy<reference>(this->dereference());
 }

The use of «reference» makes me think that the reference is intended. Is there a reason for taking address to a reference to not work? I think to remember having done it myself a couple of times, and getting the address of the original, aliased variable that way….

Содержание

  1. Compilation error on g++ 7.3.0 #23
  2. Comments
  3. Класс, который преобразует, преобразует в индекс и указатель и ссылается на контейнер
  4. Решение
  5. access by (const) reference #91
  6. Comments
  7. Ошибка: формирование указателя на ссылочный тип ‘const std:: pair &’. Я не могу понять эту ошибку
  8. Класс, который преобразует, преобразует в индекс и указатель и ссылается на контейнер
  9. Решение

Compilation error on g++ 7.3.0 #23

In file included from /usr/include/c++/7/string:52:0, from catch.hpp:207, from main.cpp:2: /usr/include/c++/7/bits/basic_string.h:693:7: note: in call to ‘std::__cxx11::basic_string & std::__cxx11::basic_string ::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits ; _Alloc = std::allocator ]’ operator=(const _CharT* __s) ^

In file included from named_type.hpp:5:0, from main.cpp:10: underlying_functionalities.hpp: In instantiation of ‘struct fluent::MethodCallable >’: underlying_functionalities.hpp:120:8: required from ‘struct fluent::Callable >’ named_type_impl.hpp:21:19: required from ‘class fluent::NamedType ’ main.cpp:283:5: required from here underlying_functionalities.hpp:115:14: error: forming pointer to reference type ‘____C_A_T_C_H____T_E_S_T____32()::A&’ T const* operator->() const < return std::addressof(this->underlying().get()); > ^

underlying_functionalities.hpp:116:8: error: forming pointer to reference type ‘____C_A_T_C_H____T_E_S_T____32()::A&’ T* operator->() < return std::addressof(this->underlying().get()); > ^

Makefile:4: recipe for target ‘main’ failed make: *** [main] Error 1 sl@acer17:

/project/NamedType$ g++ —version g++ (Ubuntu 7.3.0-27ubuntu1

18.04) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. «>

The text was updated successfully, but these errors were encountered:

Источник

Класс, который преобразует, преобразует в индекс и указатель и ссылается на контейнер

Я пытаюсь написать класс, который обращается к элементу в контейнере по его индексу. Поэтому я смогу перенаправить указанный контейнер (но это не очень важно для моей текущей проблемы). Это поможет мне избавиться от сложных конструкторов копирования.

Этот класс должен вести себя так, как будто это число (то есть индекс), и как если бы это был указатель (т.е. на который он указывает). Поэтому у меня есть обращение. Однако я получаю ошибки компилятора:

Что значит forming pointer to reference type ‘Dog&’ имею в виду? Мне действительно нужно определить -> оператор, если у меня есть неявное преобразование в указатель? Можно ли сократить paxRef синтаксис и это вызывает вышеуказанные ошибки?

Решение

Да, вам нужно явно определить operator-> даже если у вас есть неявное преобразование в указатель.

Стандарт гласит в
[Over.match.oper] / 2

Если любой из операндов имеет тип, который является классом или перечислением, пользовательская операторная функция может быть
объявил, что реализует этот оператор или пользовательское преобразование может быть необходимо для преобразования операнда
к типу, который подходит для встроенного оператора. В этом случае разрешение перегрузки используется для определения
какая операторская функция или встроенный оператор должны вызываться для реализации оператора. […]

Разрешение перегрузки затем описано в [over.match.oper] / 3, соответствующей частью для этого случая является [over.match.oper] /3.3:

Для operator, , одинарный operator & , или operator -> набор встроенных кандидатов пуст. […]

Это означает, что нет преобразований, которые позволили бы вызвать встроенный operator-> (в этом случае для Dog* ), и должно быть определение члена или не члена operator-> для вашего класса.

Относительно явной аннотации аргументов шаблона:
Вы можете обойти это, определив шаблонную вспомогательную функцию make_paxref похожий на make_tuple или же make_pair это делает вывод типа. Или вы можете подождать C ++ 17, где вывод аргументов шаблона будет также работать для конструкторов шаблонных классов 🙂

Источник

access by (const) reference #91

yet another question. I try to avoid copying whereever possible (during serialization). So when:

the compiler tells us:

with a static cast:

the compiler is happy, but apparently returns a reference to a temporary, so s is dangling.

Have you got any hints on how to access underlying memory (for string, int, . ) so we can avoid copying the values?

Thanks and cheers,
Roman

The text was updated successfully, but these errors were encountered:

I actually haven’t thought about this yet. I’ll see what I can find out.

Roman, temporary object return should be handled by RVO, which is in C++ since 199x, so I think you are overoptimizing and there is no need in storing values in const references here.

On the other hand char * can return pointer to a string stored in a json parsing buffer — which definitely would be faster than building a std::string, but that way buffer should be changed and placed at the end of the tokens.

RVO is not the point. If you’re i.e. serializing a json struct into something else, you currently have to take copies of all keys and values inside the json structure for no good reason. Instead, it would be desirable to just reference keys and values without actually copying them. This is completely unrelated to RVO.

Examples where you want to have that behaviour is when

  • writing a json structure to the wire or file via msgpack, or
  • you want to asynchroneously write data, i.e. via asio::async_write, or
  • you want to bind a json object into a prepared statement in i.e. mysql.

So instead of taking copies everywhere, you keep the source json alive, and refer to it’s memory regions during i/o operations.

Thanks and cheers,
Roman

Here is a suggestion for the functionality:

In the json class, the following public interface could be supported:

The corresponding private implementation:

plus an accessor for object keys in the iterator classes:

  • Pointers are returned instead of references because the method can be noexcept, plus a returned reference can be part of an expression which accidentally ends up in an unwanted copy.
  • No implementation for the nullptr type. That would require a little change in the json_value class.
  • This implementation is less intelligent than the get flavour of methods, since it’s not performing any conversion, and is only supported for the stored types (otherwise it would result in a conversion/copy).

I thought about the issue and I think I have a solution:

you would get a const reference to the types of basic_json .

For json::string_t , this function would be implemented as follows.

Note that string_t* is only used to choose the correct version of get_impl_ref .

What do you think? Is this what you want? If so, I can add this for the value types ( object_t , array_t , string_t , boolean_t , number_integer_t , and number_float_t ).

it seems our posts overlap 😉

I like your approach, because it’s much simpler than my way with const references. However, I have a bad feeling about returning non-const pointers to the member variables. Furthermore, I’d rather raise an exception in case of a type error than to silently return a null pointer — but that may be personal taste.

Anyway — now that there are two proposals, I would be glad to hear opinions 🙂

Hi Niels, Andras,

@nlohmann: sorry mistyping your name all the time, fixed now!

both version have their advantages. As usual, it all comes with some cost, which is responsibility here if one is dealing with raw pointers.

  • exception freeness enables you to write exception-free code (assuming -fnoexcept)
  • non-const access to underlying pointers may enable some in-place processing.
  • greater flexibility (assuming you know what you’re doing)
  • might even serve as foundation for internal handling

const reference access

  • easier access, good enough for most things
  • limited in case you really need a pointer to the underlying memory.
  • if somebody really wants to break things, he can cast away the reference both in pointers and references

My choice: both, and eventually mask out the pointer semantics via preprocessor via

Besides, I’d re-write your internal accessor to that one:

which is shorter and will run faster. I currently see no need for the reinterpret_cast, plus delegate the creation of the error message into a delegate which knows if RTTI is available or not (i.e. -fno-rtti and __GXX_RTTI under g++/llvm)

Thanks and cheers,
Roman

good point for having them both, and good point with RTTI — I shall remove all the typeid stuff.

One question: What do you mean with «might even serve as foundation for internal handling»?

I saw a lot of switch statements inside the code and asked myself if pointer-based members could somehow unify access and spare code — not sure about that. Will come back in another ticket, if so.

My 2 cents on the ptr/ref based accessors:

  • C++ has the long standing legacy of providing zero overhead abstractions, if possible. In my understanding my get_ptr proposal is that one. It’s more or less analog to the std::vector’s operator[] and at(). The first is the fast, simple, non-throwing version, the second one is the safer throwing.
  • Usage:

The good point with returning a nullptr is ease of usage. An idiomatic use of get_ptr is:

Whilst the reference based approach forces me to use a separate check, or (even worse) a catch statement.

For further study: Since get_ptr is the lowest level of the accessors, it’s also has reusability potential. E.g. get/get_impl could be refactored in a way that a front end function checks convertibility (+ handling returned nullptr by throwing an exception) and get_ptr does the rest of the job. I think this would be a good move, but not the topic of this discussion.

Niels’s concerns about safety are valid and should be addressed:

  • it should be documented that get_ptr returns a nullptr on type mismatch
  • also it should be documented either for get_ref and get_ptr that later assignments to the json object can invalidate returned pointers and references. Thus using the pointer after assignment is undefined behaviour by design.
  • i think it’s not dangerous to return a pointer in a sense, that one cannot really break the json object via the pointer (except for UB in the previous case). We’re protecting against Murphy, not Machiavelli ;).
  • also i think the preferred way of accessing members in the json object is still via get<>, because it has more rich semantics and convenience. In my understanding we’re not compromising the library here, just exposing some low-level functionality for some narrow usage.

@nlohmann: in case you’d agree, would you need help? If so, please advise (I guess some enable_if is needed to make overloads work on the public API for the get-family).

Thanks and cheers,
Roman

Hi all, thanks a lot for the lively discussion. I really appreciate this! I will have time on the weekend to integrate the ideas.

Until then, I would like to clarify some questions from my side:

  1. We agree that T get() remains as is to explicitly ask for copies of the stored values, including conversions where possible and exceptions in case of incompatibles.
  2. To allow for implicit type conversion, the operator T() will just be calling T get() .
  3. There should be a function to return a const reference to the stored values. This function should only be applicable to the basic types. In case of incompatibilities, an exception is thrown.
  4. There should be a function to return a pointer to the stored values. This function should only be applicable to the basic types. In case of incompatibilities, a null pointer is returned. Though the pointer is non-const, anything but reading values leaves the basic_json object in an undefined state.
  1. Should the function from 3. really be called get_ref , or should it be integrated into the get function. That is, should we prefer auto r = j.get () over auto r = j.get_ref () ?
  2. Same question as above: Should we get pointers via a dedicated get_ptr function ( auto ptr = j.get_ptr () ) or rather via auto ptr = j.get () ?
  3. Should operator T() be extended as well?
  4. What about non-const references?

From my point of view, I would like to keep the number of functions low and rather increase the use cases in which the existing functions work. Hence, I would answer the first three questions with yes.

Источник

Ошибка: формирование указателя на ссылочный тип ‘const std:: pair &’. Я не могу понять эту ошибку

У меня возникают некоторые ошибки при попытке использовать → в типе итератора. Когда я копаюсь в библиотеке, определяющей итератор, мне кажется, что все есть в порядке и нет причины для ошибки. Вот код, часть boost:: multi_array:

который создается с помощью const std::pair & ; то компилятор жалуется на «формирование указателя на ссылочный тип: const std:: pair &». Это внутренние, библиотечные обоснования. Для записи вот что я имею в своем коде:

и вот использование, которое вызывает проблему:

Здесь больше контекста ошибки:

ПРИМЕЧАНИЕ. Этот класс является частью boost:: multi_array (я уже писал это), и я не создаю его напрямую. Я написал выше своего экземпляра. Класс создается экземпляром boost:: multi_array следующим образом:

Использование «ссылки» заставляет меня думать, что ссылка предназначена. Есть ли причина, по которой обращение к ссылке не работает? Я думаю, помню, что сделал это сам пару раз и получал адрес оригинальной переменной с псевдонимом таким образом.

Взятие адреса ссылки не является проблемой, но возвращает указатель на базовый тип, а не указатель на ссылку. Указатели на ссылку не могут быть созданы и не имеют смысла, поскольку ссылки не могут быть восстановлены. Объявление указателя на ссылочный тип является ошибкой.

Возвращаемый тип T * поэтому не будет работать, если T является ссылочным типом. Аналогично, объявляя a mutable T , нет смысла, если T является ссылочным типом, потому что ссылки не могут быть отскок. Таким образом, operator_arrow_proxy , по-видимому, написан, чтобы ожидать не ссылки.

Если boost создает экземпляр элемента reference , который всегда является ссылочным типом, он выглядит как ошибка. Действительно, как сообщается, ошибка # 6554.

Источник

Класс, который преобразует, преобразует в индекс и указатель и ссылается на контейнер

Я пытаюсь написать класс, который обращается к элементу в контейнере по его индексу. Поэтому я смогу перенаправить указанный контейнер (но это не очень важно для моей текущей проблемы). Это поможет мне избавиться от сложных конструкторов копирования.

Этот класс должен вести себя так, как будто это число (то есть индекс), и как если бы это был указатель (т.е. на который он указывает). Поэтому у меня есть обращение. Однако я получаю ошибки компилятора:

Что значит forming pointer to reference type ‘Dog&’ имею в виду? Мне действительно нужно определить -> оператор, если у меня есть неявное преобразование в указатель? Можно ли сократить paxRef синтаксис и это вызывает вышеуказанные ошибки?

Решение

Да, вам нужно явно определить operator-> даже если у вас есть неявное преобразование в указатель.

Стандарт гласит в
[Over.match.oper] / 2

Если любой из операндов имеет тип, который является классом или перечислением, пользовательская операторная функция может быть
объявил, что реализует этот оператор или пользовательское преобразование может быть необходимо для преобразования операнда
к типу, который подходит для встроенного оператора. В этом случае разрешение перегрузки используется для определения
какая операторская функция или встроенный оператор должны вызываться для реализации оператора. […]

Разрешение перегрузки затем описано в [over.match.oper] / 3, соответствующей частью для этого случая является [over.match.oper] /3.3:

Для operator, , одинарный operator & , или operator -> набор встроенных кандидатов пуст. […]

Это означает, что нет преобразований, которые позволили бы вызвать встроенный operator-> (в этом случае для Dog* ), и должно быть определение члена или не члена operator-> для вашего класса.

Относительно явной аннотации аргументов шаблона:
Вы можете обойти это, определив шаблонную вспомогательную функцию make_paxref похожий на make_tuple или же make_pair это делает вывод типа. Или вы можете подождать C ++ 17, где вывод аргументов шаблона будет также работать для конструкторов шаблонных классов 🙂

Источник

PC running slow?

  • 1. Download ASR Pro from the website
  • 2. Install it on your computer
  • 3. Run the scan to find any malware or virus that might be lurking in your system
  • Improve the speed of your computer today by downloading this software — it will fix your PC problems.

    You should read these troubleshooting guidelines if you get an error pointer to an nt & reference error message.

    PC running slow?

    ASR Pro is the ultimate solution for your PC repair needs! Not only does it swiftly and safely diagnose and repair various Windows issues, but it also increases system performance, optimizes memory, improves security and fine tunes your PC for maximum reliability. So why wait? Get started today!

    You cannot register links. References are just aliases to help other variables.

      map , string> m; 

    The reason your company is getting this particular error is because somewhere on the map, they are picking opssetting for mapped_type , which in your case is string & . One of the surgical interventions that (as in the [] operator) is able to return a link to mapped_type :

      mapped_type & operator [] (const key_type &) 
      string && operator [] (const key_type & _Keyval) 

    Standard 8.3.4:

    There should be a few more links, no links, no linked tables, and no link references.

    On the right, I recommend that you take advantage of the typedef to make the code easier to read:

      int main (){    typedef pair  StringPair;    typedef map  StringPairMap;     Test;    StringPair p ("Fu", "Bar");    StringPairMap m;    m [make_pair ("aa", "bb")] implies checking;   Returns 0; 

    answered Jul 20 ’09 at 18:33

    error forming pointer to reference type nt&

    465k

    Previous answers prevail here. Today we have std :: reference_wrapper as part of the C ++ 11 standard:

      #include #include #include Using the std namespace;int main ()    Test; A pair of lines  p matches a pair of  ("Foo", "Bar");    map , reference_wrapper > m;    m [make_pair ("aa", "bb")] = test;    Income 0; 

    std :: reference_wrapper is implicitly converted to a full reference to its internal type, but the following does not work in some contexts. In this case, call .get () to access it.

    answered Jul 13 13 at 5:25 am

    8,543

    With boost :: reference_wrapper you can store private links in STL containers. Here’s your situation changed essentially (untested and certainly not surprisingly well written, just illustrates the point)

      #include #include #include #include int main ()   typedef std :: pair  PairType;   typedef std :: map  boost :: reference_wrapper  MapType;   std :: string verify = "Hello !!";   Card type m;   PairType pp implies std :: make_pair ("aa", "bb");   m.insert (std :: make_pair (pp, boost :: ref (test)));  MapType :: iterator it (m.find (pp));  if (what! = l. end ())         std :: cout << it-> second.get () << std :: endl;      // change the test   test = "I'm different now";   std :: cout << it-> second.get () << std :: endl;   Returns 0; 

    answered Jul 21, 2009 at 15:06

    1.548

    You cannot use references as a value to guarantee the actual structure of the model… You can use pointers instead.

    answered Jul 20 ’09 here at 18:34

    error forming pointer to reference type nt&

    1.594

    Basically, the point is that you can use links in containers. Of course, IF you start to properly prepare your class AND your container, you can. I copy it with the following two simple vector dishes: vectoref , which modifies std :: vector <> , and the similar vec used. the scratch is realized.

      #include #include // requires compilation with --std = c ++ 11 (at least)Using the std namespace;Class A  int _a; // this is our real data  A * _p; // to "trick" the compiler  publicly:  A (interval m = 0): _p (0) _a (n), cout << "Constructor (" << such << "," << _a << ")  n";  // constructor used by the corresponding initializer_list (trick the compiler)  A (const A & r): _p (const_cast  (& r))   cout << "Copy constructor (" << this approach << "<-" << & r << ")  n";  unnecessary print () const cout << "Practical example:" << this << "," << _a << " n";  ~ A () cout << "A (" << this << "," << _a << ") Destructor.  N"; // just to know what is being copied implicitly  Operator A & = (const A & r)    cout << "Copied instance (" << this << "," << _a << ")  n";    _a = r._a; _p means r._p;    return * this;    // just in case your company wants to check if a copy is organic, natural or fake  bool is_fake () const return _p! = 0;  A * ptr () const return _p;;Model class vec // vector class with initializer_list of links A !!  publicly:  const T * a [sz]; // put as pointer, get as links  // because assigning to a link triggers a call to the copy operator  int heart;  vec (): cur (0) vec (std :: initializer_list  l): cur (0)    cout << "create with init list.  n";    (auto & for w not: l) // wait for fake items      a [cur ++] = t.ptr ();    const T & operator [] I (int) return * a [i];  // expects clean items  vec & push_back (const T & r) in [cur ++] implies & r; return * this;  void copy_from (vec && r)    for I (int means 0; i class vectoref:public vector  // indistinguishable from vec, but extends std :: vector <>  Choice size_type = typename vector  :: size_type;  publicly:  Vector ref ()  vector (std :: initializer_list  l)    cout << "build from initialization list.  n";    only for (auto & t: l) // wait for elements artificial vector  :: push_back (t.ptr ());    const T & operator [] (size_type i) return * vector  :: at (i);  // expects clean items  vector & T & push_back (const r)   vector  :: push_back (& ​​r); undo * this;  void copy_from (const vectoref && r)    defined for (size_type i = 0; i  :: push_back (r [i]);  ;Class X // user connected to initializer_list publicly:  X ()  void f (initializer_list  l) const    cout << "In f (...):  n";    for (auto and from a to l)      A. ptr () -> print (); ;int main ()  Aa (7), b (24), c (80);  cout << "----------------------------------  n";  Control vector  wa, a, b, c; // use the following line as an alternative  // vec  wa, a, b, c; // 5th undefined element  w [0] .print ();  w [3] .print ();  cout << "----------------------------------  n";  Xx; x.f (a, b, c, a, b, c, b, a);  cost << "=====================================  n";  Returns 0; 

    answered Dec 10 ’17 at 17:31

    59

    Improve the speed of your computer today by downloading this software — it will fix your PC problems.

    Bugfixes Und Probleme Beim Erstellen Von Zeigern Auf Die Referenzauswahl Nt &
    Correzioni Di Bug E Complicazioni Durante La Creazione Di Puntatori All’opzione Di Riferimento Nt &
    Bugfixes En Daardoor Fouten Bij Het Maken Van Verwijzingen Naar Het Referentieassortiment Nt &
    Correction De Bugs Et Inconvénients Lors De La Création De Pointeurs Vers Le Pointage De Référence Dans Nt &
    참조 유형 Nt &
    Исправлены ошибки и ошибки, при которых создавались указатели на ссылочный тип Nt &
    Felkorrigeringar Och Fel Vid Konstruktion Av Pekare Till Referenstypen Nt &
    Correções De Bugs E Erros No Caso De Criação De Ponteiros Para O Tipo De Referência Nt &
    Obróbki Błędów I Błędy Podczas Tworzenia Wskaźników Do Tego Typu Referencji Nt &
    Correcciones De Errores Y Errores Al Crear Punteros Al Tipo De Referencia Nt &

    I have installed the STL for arduino, and it has been working fine. Then I tried to create a vector using a custom class, and it gave me a massive error message. When using it on primitive data types (ex. int) it works fine, but in any one of my own classes (including classes from sample code) it gives this error:

    Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"
    
    Build options changed, rebuilding all
    
    
    
    C:Program Files (x86)Arduinohardwaretoolsavr/bin/avr-g++ -c -g -Os -w - fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD   -std=gnu++11 -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10603 -  DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:Program Files   (x86)Arduinohardwarearduinoavrcoresarduino -IC:Program Files   (x86)Arduinohardwarearduinoavrvariantsstandard   C:UsersOWNERAppDataLocalTempbuild7240665633604233053.tmpNavigation.cpp -o    C:UsersOWNERAppDataLocalTempbuild7240665633604233053.tmpNavigation.cpp.o 
    
    In file included from c:program files     (x86)arduinohardwaretoolsavravrincludevector:33:0,
    
                     from Navigation.ino:2:
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h: In instantiation   of 'void std::__destroy_aux(_ForwardIterator, _ForwardIterator, __false_type)   [with _ForwardIterator = Obstacle*]':
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h:78:55:   required  from 'void std::__destroy(_ForwardIterator, _ForwardIterator, _Tp*) [with  _ForwardIterator = Obstacle*; _Tp = Obstacle]'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h:83:51:   required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = Obstacle*]'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h:115:27:   required  from 'void std::destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = Obstacle*]'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:284:42:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = Obstacle; _Alloc = std::allocator<Obstacle>]'
    
    Navigation.ino:36:23:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h:66:22: error: 'destroy' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
    
         destroy(&*__first);
    
                      ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_construct.h:114:13: note: 'template<class _ForwardIterator> void std::destroy(_ForwardIterator, _ForwardIterator)' declared here, later in the translation unit
    
     inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
    
                 ^
    
    Error compiling.
    

    EDIT:
    Here is the code:

    #include <iterator>
    #include <vector>
    #include <pnew.cpp>
    
    class Test {
    public:
        int i;
    };
    std::vector<Test> test;
    

    Change the last line to

    std::vector<Test&> test
    

    and:

            Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"
    
    C:Program Files (x86)Arduinohardwaretoolsavr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -std=gnu++11 -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10603 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:Program Files (x86)Arduinohardwarearduinoavrcoresarduino -IC:Program Files (x86)Arduinohardwarearduinoavrvariantsstandard C:UsersOWNERAppDataLocalTempbuild7240665633604233053.tmpNavigation.cpp -o C:UsersOWNERAppDataLocalTempbuild7240665633604233053.tmpNavigation.cpp.o 
    
    In file included from c:program files (x86)arduinohardwaretoolsavravrincludevector:35:0,
    
                     from Navigation.ino:2:
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h: In instantiation of 'class std::_Vector_alloc_base<Obstacle&, std::allocator<Obstacle&>, true>':
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:101:8:   required from 'struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:155:7:   required from 'class std::vector<Obstacle&>'
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:89:8: error: forming pointer to reference type 'Obstacle&'
    
       _Tp* _M_start;
    
            ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:90:8: error: forming pointer to reference type 'Obstacle&'
    
       _Tp* _M_finish;
    
            ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:91:8: error: forming pointer to reference type 'Obstacle&'
    
       _Tp* _M_end_of_storage;
    
            ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:94:8: error: forming pointer to reference type 'Obstacle&'
    
       _Tp* _M_allocate(size_t __n)
    
            ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:96:8: error: forming pointer to reference type 'Obstacle&'
    
       void _M_deallocate(_Tp* __p, size_t __n)
    
            ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h: In instantiation of 'class std::vector<Obstacle&>':
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:165:23: error: forming pointer to reference type 'std::vector<Obstacle&>::value_type {aka Obstacle&}'
    
       typedef value_type* pointer;
    
                           ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:166:29: error: forming pointer to reference type 'std::vector<Obstacle&>::value_type {aka Obstacle&}'
    
       typedef const value_type* const_pointer;
    
                                 ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:167:23: error: forming pointer to reference type 'std::vector<Obstacle&>::value_type {aka Obstacle&}'
    
       typedef value_type* iterator;
    
                           ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:168:29: error: forming pointer to reference type 'std::vector<Obstacle&>::value_type {aka Obstacle&}'
    
       typedef const value_type* const_iterator;
    
                                 ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:178:49: error: forming pointer to reference type 'Obstacle&'
    
       typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    
                                                     ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:179:43: error: forming pointer to reference type 'Obstacle&'
    
       typedef std::reverse_iterator<iterator> reverse_iterator;
    
                                               ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:189:16: error: no members matching 'std::vector<Obstacle&>::_Base {aka std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}::_M_allocate' in 'std::vector<Obstacle&>::_Base {aka struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}'
    
       using _Base::_M_allocate;
    
                    ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:190:16: error: no members matching 'std::vector<Obstacle&>::_Base {aka std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}::_M_deallocate' in 'std::vector<Obstacle&>::_Base {aka struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}'
    
       using _Base::_M_deallocate;
    
                    ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:191:16: error: no members matching 'std::vector<Obstacle&>::_Base {aka std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}::_M_start' in 'std::vector<Obstacle&>::_Base {aka struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}'
    
       using _Base::_M_start;
    
                    ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:192:16: error: no members matching 'std::vector<Obstacle&>::_Base {aka std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}::_M_finish' in 'std::vector<Obstacle&>::_Base {aka struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}'
    
       using _Base::_M_finish;
    
                    ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:193:16: error: no members matching 'std::vector<Obstacle&>::_Base {aka std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}::_M_end_of_storage' in 'std::vector<Obstacle&>::_Base {aka struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >}'
    
       using _Base::_M_end_of_storage;
    
                    ^
    
    In file included from c:program files (x86)arduinohardwaretoolsavravrincludeiosfwd:22:0,
    
                     from c:program files (x86)arduinohardwaretoolsavravrincludeiterator:35,
    
                     from Navigation.ino:1:
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_alloc.h: In instantiation of 'class std::allocator<Obstacle&>':
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_alloc.h:638:22: error: forming pointer to reference type 'Obstacle&'
    
       typedef _Tp*       pointer;
    
                          ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_alloc.h:639:22: error: forming pointer to reference type 'Obstacle&'
    
       typedef const _Tp* const_pointer;
    
                          ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_alloc.h:658:8: error: forming pointer to reference type 'Obstacle&'
    
       _Tp* allocate(size_type __n, const void* = 0) {
    
            ^
    
    Navigation.ino: In constructor 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Obstacle&>]':
    
    Navigation.ino:36:24: note:   when instantiating default argument for call to std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Obstacle&>]
    
    In file included from c:program files (x86)arduinohardwaretoolsavravrincludevector:35:0,
    
                     from Navigation.ino:2:
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>]':
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:240:16:   required from 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Obstacle&>]'
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:117:21: error: 'struct std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >' has no member named '_M_deallocate'
    
       ~_Vector_base() { this->_M_deallocate(_Base::_M_start, _Base::_M_end_of_storage - _Base::_M_start); }
    
                         ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:117:21: error: '_M_start' is not a member of 'std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >::_Base {aka std::_Vector_alloc_base<Obstacle&, std::allocator<Obstacle&>, true>}'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:117:83: error: '_M_start' is not a member of 'std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >::_Base {aka std::_Vector_alloc_base<Obstacle&, std::allocator<Obstacle&>, true>}'
    
       ~_Vector_base() { this->_M_deallocate(_Base::_M_start, _Base::_M_end_of_storage - _Base::_M_start); }
    
                                                                                       ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:117:83: error: '_M_end_of_storage' is not a member of 'std::_Vector_base<Obstacle&, std::allocator<Obstacle&> >::_Base {aka std::_Vector_alloc_base<Obstacle&, std::allocator<Obstacle&>, true>}'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h: In instantiation of 'std::_Vector_alloc_base<_Tp, _Allocator, true>::_Vector_alloc_base(const allocator_type&) [with _Tp = Obstacle&; _Allocator = std::allocator<Obstacle&>; std::_Vector_alloc_base<_Tp, _Allocator, true>::allocator_type = std::allocator<Obstacle&>]':
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:110:54:   required from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(const allocator_type&) [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>; std::_Vector_base<_Tp, _Alloc>::allocator_type = std::allocator<Obstacle&>]'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:240:16:   required from 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Obstacle&>]'
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:85:53: error: using invalid field 'std::_Vector_alloc_base<_Tp, _Allocator, true>::_M_start'
    
         : _M_start(0), _M_finish(0), _M_end_of_storage(0) 
    
                                                         ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:85:53: error: using invalid field 'std::_Vector_alloc_base<_Tp, _Allocator, true>::_M_finish'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:85:53: error: using invalid field 'std::_Vector_alloc_base<_Tp, _Allocator, true>::_M_end_of_storage'
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = Obstacle&; _Alloc = std::allocator<Obstacle&>]':
    
    Navigation.ino:36:24:   required from here
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:284:42: error: '_M_start' was not declared in this scope
    
       ~vector() { destroy(_M_start, _M_finish); }
    
                                              ^
    
    c:program files (x86)arduinohardwaretoolsavravrincludestl_vector.h:284:42: error: '_M_finish' was not declared in this scope
    
    Error compiling.
    

    Предположим есть класс A:

    A.h

    #include <vector>
    
    #ifndef UN1_A_H
    #define UN1_A_H
    
    #include "B.h"
    
    class A {
    public:
        std::vector<B&> get();
    };
    
    
    #endif //UN1_A_H
    

    A.cpp

    #include "A.h"
    #include "B.h"
    
    std::vector<B &> A::get() {
        std::vector<B&> bs;
    
        bs.push_back(*(new B()));
        bs.push_back(*(new B()));
    
        return bs;
    }
    

    И есть класс B, в котором ничего нет.

    Почему я не могу скомпилировать следующий код?:

    #include "A.h"
    #include "B.h"
    
    int main() {
        A& a = *(new A());
        B& b = a.get()[0];
    }
    

    Вывод:

    /usr/include/c++/7/bits/alloc_traits.h: In instantiation of ‘struct std::allocator_traits<std::allocator<B&> >’:
    /usr/include/c++/7/ext/alloc_traits.h:50:10:   required from ‘struct __gnu_cxx::__alloc_traits<std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:77:21:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:8:25:   required from here
    /usr/include/c++/7/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘B&’
           using pointer = _Tp*;
                               ^
    /usr/include/c++/7/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘B&’
           using const_pointer = const _Tp*;
                                           ^
    In file included from /usr/include/c++/7/bits/stl_construct.h:61:0,
                     from /usr/include/c++/7/vector:62,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator<B&> >’:
    /usr/include/c++/7/bits/stl_vector.h:77:21:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:8:25:   required from here
    /usr/include/c++/7/ext/alloc_traits.h:66:23: error: no members matching ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka std::allocator_traits<std::allocator<B&> >}::allocate’ in ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka struct std::allocator_traits<std::allocator<B&> >}’
         using _Base_type::allocate;
                           ^~~~~~~~
    /usr/include/c++/7/ext/alloc_traits.h:67:23: error: no members matching ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka std::allocator_traits<std::allocator<B&> >}::deallocate’ in ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka struct std::allocator_traits<std::allocator<B&> >}’
         using _Base_type::deallocate;
                           ^~~~~~~~~~
    In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
                     from /usr/include/c++/7/bits/allocator.h:46,
                     from /usr/include/c++/7/vector:61,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘class __gnu_cxx::new_allocator<B&>’:
    /usr/include/c++/7/bits/allocator.h:108:11:   required from ‘class std::allocator<B&>’
    /usr/include/c++/7/bits/stl_vector.h:81:14:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’
    /usr/include/c++/7/bits/stl_vector.h:166:20:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:8:25:   required from here
    /usr/include/c++/7/ext/new_allocator.h:63:26: error: forming pointer to reference type ‘B&’
           typedef _Tp*       pointer;
                              ^~~~~~~
    /usr/include/c++/7/ext/new_allocator.h:64:26: error: forming pointer to reference type ‘B&’
           typedef const _Tp* const_pointer;
                              ^~~~~~~~~~~~~
    In file included from /usr/include/c++/7/vector:61:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/allocator.h: In instantiation of ‘class std::allocator<B&>’:
    /usr/include/c++/7/bits/stl_vector.h:81:14:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’
    /usr/include/c++/7/bits/stl_vector.h:166:20:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:8:25:   required from here
    /usr/include/c++/7/bits/allocator.h:113:26: error: forming pointer to reference type ‘B&’
           typedef _Tp*       pointer;
                              ^~~~~~~
    /usr/include/c++/7/bits/allocator.h:114:26: error: forming pointer to reference type ‘B&’
           typedef const _Tp* const_pointer;
                              ^~~~~~~~~~~~~
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘class std::vector<B&>’:
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:8:25:   required from here
    /usr/include/c++/7/bits/stl_vector.h:247:20: error: no members matching ‘std::vector<B&>::_Base {aka std::_Vector_base<B&, std::allocator<B&> >}::_M_allocate’ in ‘std::vector<B&>::_Base {aka struct std::_Vector_base<B&, std::allocator<B&> >}’
           using _Base::_M_allocate;
                        ^~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:248:20: error: no members matching ‘std::vector<B&>::_Base {aka std::_Vector_base<B&, std::allocator<B&> >}::_M_deallocate’ in ‘std::vector<B&>::_Base {aka struct std::_Vector_base<B&, std::allocator<B&> >}’
           using _Base::_M_deallocate;
                        ^~~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:920:7: error: forming pointer to reference type ‘B&’
           data() _GLIBCXX_NOEXCEPT
           ^~~~
    /usr/include/c++/7/bits/stl_vector.h:924:7: error: forming pointer to reference type ‘B&’
           data() const _GLIBCXX_NOEXCEPT
           ^~~~
    /usr/include/c++/7/bits/stl_vector.h:953:7: error: ‘void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = B&; _Alloc = std::allocator<B&>; std::vector<_Tp, _Alloc>::value_type = B&]’ cannot be overloaded
           push_back(value_type&& __x)
           ^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:939:7: error: with ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = B&; _Alloc = std::allocator<B&>; std::vector<_Tp, _Alloc>::value_type = B&]’
           push_back(const value_type& __x)
           ^~~~~~~~~
    In file included from /usr/include/c++/7/bits/stl_vector.h:63:0,
                     from /usr/include/c++/7/vector:64,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/initializer_list: In instantiation of ‘class std::initializer_list<B&>’:
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:14:12:   required from here
    /usr/include/c++/7/initializer_list:54:26: error: forming pointer to reference type ‘B&’
           typedef const _E*  iterator;
                              ^~~~~~~~
    /usr/include/c++/7/initializer_list:55:26: error: forming pointer to reference type ‘B&’
           typedef const _E*  const_iterator;
                              ^~~~~~~~~~~~~~
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = B&; _Alloc = std::allocator<B&>]’:
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:9:21:   required from here
    /usr/include/c++/7/bits/stl_vector.h:434:37: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_start’; did you mean ‘_M_swap_data’?
           { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                           ~~~~~~~~~~~~~~^~~~~~~~
                           _M_swap_data
    /usr/include/c++/7/bits/stl_vector.h:434:61: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_finish’
           { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                                                   ~~~~~~~~~~~~~~^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = B&; _Alloc = std::allocator<B&>; std::vector<_Tp, _Alloc>::value_type = B&]’:
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:11:28:   required from here
    /usr/include/c++/7/bits/stl_vector.h:941:20: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_finish’
      if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
          ~~~~~~~~~~~~~~^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:941:47: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_end_of_storage’
      if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
                                     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:943:60: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_finish’
          _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
                                                  ~~~~~~~~~~~~~~^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:945:22: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_finish’
          ++this->_M_impl._M_finish;
            ~~~~~~~~~~~~~~^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:948:25: error: no matching function for call to ‘end()’
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/bits/stl_vector.h:63:0,
                     from /usr/include/c++/7/vector:64,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/initializer_list:99:5: note: candidate: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
         end(initializer_list<_Tp> __ils) noexcept
         ^~~
    /usr/include/c++/7/initializer_list:99:5: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/vector:66:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/range_access.h:68:5: note: candidate: template<class _Container> decltype (__cont.end()) std::end(_Container&)
         end(_Container& __cont) -> decltype(__cont.end())
         ^~~
    /usr/include/c++/7/bits/range_access.h:68:5: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/vector:66:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/range_access.h:78:5: note: candidate: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
         end(const _Container& __cont) -> decltype(__cont.end())
         ^~~
    /usr/include/c++/7/bits/range_access.h:78:5: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/vector:66:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/range_access.h:97:5: note: candidate: template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
         end(_Tp (&__arr)[_Nm])
         ^~~
    /usr/include/c++/7/bits/range_access.h:97:5: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/vector:66:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/range_access.h:106:31: note: candidate: template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
       template<typename _Tp> _Tp* end(valarray<_Tp>&);
                                   ^~~
    /usr/include/c++/7/bits/range_access.h:106:31: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    In file included from /usr/include/c++/7/vector:66:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/range_access.h:107:37: note: candidate: template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
       template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
                                         ^~~
    /usr/include/c++/7/bits/range_access.h:107:37: note:   template argument deduction/substitution failed:
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.cpp:5:
    /usr/include/c++/7/bits/stl_vector.h:948:25: note:   candidate expects 1 argument, 0 provided
        _M_realloc_insert(end(), __x);
                          ~~~^~
    /usr/include/c++/7/bits/stl_vector.h:948:21: error: ‘_M_realloc_insert’ was not declared in this scope
        _M_realloc_insert(end(), __x);
        ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = B&; _Alloc = std::allocator<B&>]’:
    /usr/include/c++/7/bits/stl_vector.h:263:15:   required from ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:9:21:   required from here
    /usr/include/c++/7/bits/stl_vector.h:162:37: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_start’; did you mean ‘_M_swap_data’?
           { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
                           ~~~~~~~~~~~~~~^~~~~~~~
                           _M_swap_data
    /usr/include/c++/7/bits/stl_vector.h:162:61: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_end_of_storage’
           { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
                                                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:163:25: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_start’; did you mean ‘_M_swap_data’?
             - this->_M_impl._M_start); }
               ~~~~~~~~~~~~~~^~~~~~~~
               _M_swap_data
    /usr/include/c++/7/bits/stl_vector.h:162:22: error: ‘_M_deallocate’ was not declared in this scope
           { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             - this->_M_impl._M_start); }
             ~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl() [with _Tp = B&; _Alloc = std::allocator<B&>]’:
    /usr/include/c++/7/bits/stl_vector.h:127:17:   required from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base() [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /usr/include/c++/7/bits/stl_vector.h:263:15:   required from ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:9:21:   required from here
    /usr/include/c++/7/bits/stl_vector.h:89:65: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_start’
      : _Tp_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage()
                                                                     ^
    /usr/include/c++/7/bits/stl_vector.h:89:65: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_finish’
    /usr/include/c++/7/bits/stl_vector.h:89:65: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_end_of_storage’
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl(std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type&&) [with _Tp = B&; _Alloc = std::allocator<B&>; std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type = std::allocator<B&>]’:
    /usr/include/c++/7/bits/stl_vector.h:145:53:   required from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::_Vector_base<_Tp, _Alloc>&&) [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /usr/include/c++/7/bits/stl_vector.h:345:29:   required from ‘std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:14:12:   required from here
    /usr/include/c++/7/bits/stl_vector.h:99:47: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_start’
        _M_start(), _M_finish(), _M_end_of_storage()
                                                   ^
    /usr/include/c++/7/bits/stl_vector.h:99:47: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_finish’
    /usr/include/c++/7/bits/stl_vector.h:99:47: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_end_of_storage’
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘void std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_swap_data(std::_Vector_base<_Tp, _Alloc>::_Vector_impl&) [with _Tp = B&; _Alloc = std::allocator<B&>]’:
    /usr/include/c++/7/bits/stl_vector.h:146:9:   required from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::_Vector_base<_Tp, _Alloc>&&) [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /usr/include/c++/7/bits/stl_vector.h:345:29:   required from ‘std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = B&; _Alloc = std::allocator<B&>]’
    /home/wcobalt/Files/BoAaP/2/un1/A.cpp:14:12:   required from here
    /usr/include/c++/7/bits/stl_vector.h:105:14: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_start’
        std::swap(_M_start, __x._M_start);
                  ^~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:105:28: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_start’; did you mean ‘_M_swap_data’?
        std::swap(_M_start, __x._M_start);
                            ~~~~^~~~~~~~
                            _M_swap_data
    /usr/include/c++/7/bits/stl_vector.h:106:14: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_finish’
        std::swap(_M_finish, __x._M_finish);
                  ^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:106:29: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_finish’
        std::swap(_M_finish, __x._M_finish);
                             ~~~~^~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:107:14: error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_end_of_storage’
        std::swap(_M_end_of_storage, __x._M_end_of_storage);
                  ^~~~~~~~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:107:37: error: ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’ has no member named ‘_M_end_of_storage’
        std::swap(_M_end_of_storage, __x._M_end_of_storage);
                                     ~~~~^~~~~~~~~~~~~~~~~
    CMakeFiles/un1.dir/build.make:75: recipe for target 'CMakeFiles/un1.dir/A.cpp.o' failed
    make[3]: *** [CMakeFiles/un1.dir/A.cpp.o] Error 1
    make[3]: *** Waiting for unfinished jobs....
    In file included from /usr/include/c++/7/ext/alloc_traits.h:36:0,
                     from /usr/include/c++/7/bits/basic_string.h:40,
                     from /usr/include/c++/7/string:52,
                     from /usr/include/c++/7/bits/locale_classes.h:40,
                     from /usr/include/c++/7/bits/ios_base.h:41,
                     from /usr/include/c++/7/ios:42,
                     from /usr/include/c++/7/ostream:38,
                     from /usr/include/c++/7/iostream:39,
                     from /home/wcobalt/Files/BoAaP/2/un1/main.cpp:1:
    /usr/include/c++/7/bits/alloc_traits.h: In instantiation of ‘struct std::allocator_traits<std::allocator<B&> >’:
    /usr/include/c++/7/ext/alloc_traits.h:50:10:   required from ‘struct __gnu_cxx::__alloc_traits<std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:77:21:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/main.cpp:7:18:   required from here
    /usr/include/c++/7/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘B&’
           using pointer = _Tp*;
                               ^
    /usr/include/c++/7/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘B&’
           using const_pointer = const _Tp*;
                                           ^
    In file included from /usr/include/c++/7/bits/basic_string.h:40:0,
                     from /usr/include/c++/7/string:52,
                     from /usr/include/c++/7/bits/locale_classes.h:40,
                     from /usr/include/c++/7/bits/ios_base.h:41,
                     from /usr/include/c++/7/ios:42,
                     from /usr/include/c++/7/ostream:38,
                     from /usr/include/c++/7/iostream:39,
                     from /home/wcobalt/Files/BoAaP/2/un1/main.cpp:1:
    /usr/include/c++/7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator<B&> >’:
    /usr/include/c++/7/bits/stl_vector.h:77:21:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/main.cpp:7:18:   required from here
    /usr/include/c++/7/ext/alloc_traits.h:66:23: error: no members matching ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka std::allocator_traits<std::allocator<B&> >}::allocate’ in ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka struct std::allocator_traits<std::allocator<B&> >}’
         using _Base_type::allocate;
                           ^~~~~~~~
    /usr/include/c++/7/ext/alloc_traits.h:67:23: error: no members matching ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka std::allocator_traits<std::allocator<B&> >}::deallocate’ in ‘__gnu_cxx::__alloc_traits<std::allocator<B&> >::_Base_type {aka struct std::allocator_traits<std::allocator<B&> >}’
         using _Base_type::deallocate;
                           ^~~~~~~~~~
    In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
                     from /usr/include/c++/7/bits/allocator.h:46,
                     from /usr/include/c++/7/string:41,
                     from /usr/include/c++/7/bits/locale_classes.h:40,
                     from /usr/include/c++/7/bits/ios_base.h:41,
                     from /usr/include/c++/7/ios:42,
                     from /usr/include/c++/7/ostream:38,
                     from /usr/include/c++/7/iostream:39,
                     from /home/wcobalt/Files/BoAaP/2/un1/main.cpp:1:
    /usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘class __gnu_cxx::new_allocator<B&>’:
    /usr/include/c++/7/bits/allocator.h:108:11:   required from ‘class std::allocator<B&>’
    /usr/include/c++/7/bits/stl_vector.h:81:14:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’
    /usr/include/c++/7/bits/stl_vector.h:166:20:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/main.cpp:7:18:   required from here
    /usr/include/c++/7/ext/new_allocator.h:63:26: error: forming pointer to reference type ‘B&’
           typedef _Tp*       pointer;
                              ^~~~~~~
    /usr/include/c++/7/ext/new_allocator.h:64:26: error: forming pointer to reference type ‘B&’
           typedef const _Tp* const_pointer;
                              ^~~~~~~~~~~~~
    In file included from /usr/include/c++/7/string:41:0,
                     from /usr/include/c++/7/bits/locale_classes.h:40,
                     from /usr/include/c++/7/bits/ios_base.h:41,
                     from /usr/include/c++/7/ios:42,
                     from /usr/include/c++/7/ostream:38,
                     from /usr/include/c++/7/iostream:39,
                     from /home/wcobalt/Files/BoAaP/2/un1/main.cpp:1:
    /usr/include/c++/7/bits/allocator.h: In instantiation of ‘class std::allocator<B&>’:
    /usr/include/c++/7/bits/stl_vector.h:81:14:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >::_Vector_impl’
    /usr/include/c++/7/bits/stl_vector.h:166:20:   required from ‘struct std::_Vector_base<B&, std::allocator<B&> >’
    /usr/include/c++/7/bits/stl_vector.h:216:11:   required from ‘class std::vector<B&>’
    /home/wcobalt/Files/BoAaP/2/un1/main.cpp:7:18:   required from here
    /usr/include/c++/7/bits/allocator.h:113:26: error: forming pointer to reference type ‘B&’
           typedef _Tp*       pointer;
                              ^~~~~~~
    /usr/include/c++/7/bits/allocator.h:114:26: error: forming pointer to reference type ‘B&’
           typedef const _Tp* const_pointer;
                              ^~~~~~~~~~~~~
    In file included from /usr/include/c++/7/vector:64:0,
                     from /home/wcobalt/Files/BoAaP/2/un1/A.h:5,
                     from /home/wcobalt/Files/BoAaP/2/un1/main.cpp:2:
    /usr/include/c++/7/bits/stl_vector.h: In instantiation of ‘class std::vector<B&>’:
    /home/wcobalt/Files/BoAaP/2/un1/main.cpp:7:18:   required from here
    /usr/include/c++/7/bits/stl_vector.h:247:20: error: no members matching ‘std::vector<B&>::_Base {aka std::_Vector_base<B&, std::allocator<B&> >}::_M_allocate’ in ‘std::vector<B&>::_Base {aka struct std::_Vector_base<B&, std::allocator<B&> >}’
           using _Base::_M_allocate;
                        ^~~~~~~~~~~
    /usr/include/c++/7/bits/stl_vector.h:248:20: error: no members matching ‘std::vector<B&>::_Base {aka std::_Vector_base<B&, std::allocator<B&> >}::_M_deallocate’ in ‘std::vector<B&>::_Base {aka struct std::_Vector_base<B&, std::allocator<B&> >}’
           using _Base::_M_deallocate;
                       ^~~~~~~~~~~~~
    

    GCC gives me a strange error.

    SourceFile.cpp:17:   instantiated from here
    /usr/include/c++/3.2.2/bits/stl_vector.h:115: forming pointer to reference type 
       `Line&''
    /usr/include/c++/3.2.2/bits/stl_vector.h:116: forming pointer to reference type 
       `Line&''
    /usr/include/c++/3.2.2/bits/stl_vector.h:117: forming pointer to reference type 
       `Line&''
    /usr/include/c++/3.2.2/bits/stl_vector.h:121: forming pointer to reference type 
       `Line&''
    /usr/include/c++/3.2.2/bits/stl_vector.h:123: forming pointer to reference type 

    The pice of code that generates the error.

     std::vector lines;  

    I»m not a C++ expert, but I think that line is correct.

    http://www.cis.gsu.edu/~shong/oojokes/

    http://www.cis.gsu.edu/~shong/oojokes/

    You can»t make a vector of references; they»re a type designed for passing around, not storing. The library can»t work with them internally because it does processing that assumes it can take pointers to the objects. That»s kinda icky for references, because they only ever appear on the stack (I think). Store either Line»s or Line*»s.

    Thanks, I»ll use pointers instead.

    http://www.cis.gsu.edu/~shong/oojokes/

    I could swear the proper format was something like this:

    std::vector <Line*> lines; 

    References are for passing, STL gets kind of weird about them. Use pointers for now…

    EDIT: Aw crap, I get it now. Stupid HTML protection
    EDIT #2: $*#@!

    ravuya: [Resist everyone][I am your only friend. Click, now .]

    [edited by — ravuya on May 24, 2004 8:23:34 PM]

    Ravuya — if you use &lt; for your opening <, it will not be interpreted as an HTML tag.

    “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
    — Brian W. Kernighan

    «Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.»
    — Brian W. Kernighan

    Я пытаюсь написать класс, который обращается к элементу в контейнере по его индексу. Поэтому я смогу перенаправить указанный контейнер (но это не очень важно для моей текущей проблемы). Это поможет мне избавиться от сложных конструкторов копирования.

    Этот класс должен вести себя так, как будто это число (то есть индекс), и как если бы это был указатель (т.е. на который он указывает). Поэтому у меня есть обращение. Однако я получаю ошибки компилятора:

    In instantiation of 'class paxRef<Dog&, std::vector<Dog> >':
    34:47: required from here
    13:5: error: forming pointer to reference type 'Dog&'
    In function 'int main()':
    37:7: error: base operand of '->' has non-pointer type 'paxRef<Dog&, std::vector<Dog> >'
    38:7: error: base operand of '->' has non-pointer type 'paxRef<Dog&, std::vector<Dog> >'
    44:43: error: base operand of '->' has non-pointer type 'paxRef<Dog&, std::vector<Dog> >'
    45:43: error: base operand of '->' has non-pointer type 'paxRef<Dog&, std::vector<Dog> >'
    

    Что значит forming pointer to reference type 'Dog&' имею в виду? Мне действительно нужно определить ->оператор, если у меня есть неявное преобразование в указатель? Можно ли сократить paxRef<decltype(v.back()), decltype(v)> синтаксис и это вызывает вышеуказанные ошибки?

    Это мой код:

    #include <iostream>
    #include <string>
    #include <vector>
    
    template <class T, class C>
    class paxRef
    {
    public:
    paxRef(size_t index, C* container) : _index(index), _container(container) { }
    //implicit conversion
    operator size_t() const { return _index; }
    operator T*() { return &(_container->at(_index)); }
    //operator ->() { return T*(); } // Do I need to define the -> operator if I already have a pointer-conversion operator?
    private:
    size_t _index;
    C* _container;
    };class Dog
    {
    public:
    std::string bark() { return _sound; }
    void setName(std::string sound) { _sound=sound; }
    private:
    std::string _sound = "Wuff";
    };int main()
    {
    std::vector<Dog> v(5);
    paxRef<decltype(v.back()), decltype(v)> r2(2, &v); // Very verbos.
    paxRef<decltype(v.back()), decltype(v)> r4(4, &v); // Can I drop the < ... > part somehow?
    
    r2->setName("Bello");
    r4->setName("Fatty");
    
    for(size_t i{ 0 }; i<v.size(); ++i)
    std::cout<<"Dog at "<<i<<" says "<<v.at(i).bark()<<std::endl;
    
    std::cout<<std::endl;
    std::cout<<"ref at "<<r2<<" says "<<r2->bark()<<std::endl;
    std::cout<<"ref at "<<r4<<" says "<<r4->bark()<<std::endl;
    }
    

    0

    Решение

    Да, вам нужно явно определить operator-> даже если у вас есть неявное преобразование в указатель.

    Стандарт гласит в
    [Over.match.oper] / 2

    Если любой из операндов имеет тип, который является классом или перечислением, пользовательская операторная функция может быть
    объявил, что реализует этот оператор или пользовательское преобразование может быть необходимо для преобразования операнда
    к типу, который подходит для встроенного оператора. В этом случае разрешение перегрузки используется для определения
    какая операторская функция или встроенный оператор должны вызываться для реализации оператора. […]

    Разрешение перегрузки затем описано в [over.match.oper] / 3, соответствующей частью для этого случая является [over.match.oper] /3.3:

    Для operator,, одинарный operator &, или operator ->набор встроенных кандидатов пуст. […]

    Это означает, что нет преобразований, которые позволили бы вызвать встроенный operator-> (в этом случае для Dog*), и должно быть определение члена или не члена operator-> для вашего класса.

    Относительно явной аннотации аргументов шаблона:
    Вы можете обойти это, определив шаблонную вспомогательную функцию make_paxref похожий на make_tuple или же make_pair это делает вывод типа. Или вы можете подождать C ++ 17, где вывод аргументов шаблона будет также работать для конструкторов шаблонных классов 🙂

    1

    Другие решения

    Других решений пока нет …

    У меня возникают некоторые ошибки при попытке использовать → в типе итератора. Когда я копаюсь в библиотеке, определяющей итератор, мне кажется, что все есть в порядке и нет причины для ошибки. Вот код, часть boost:: multi_array:

    template <class T>
    struct operator_arrow_proxy
    {
    operator_arrow_proxy(T const& px) : value_(px) {}
    T* operator->() const { return &value_; }
    // This function is needed for MWCW and BCC, which won't call operator->
    // again automatically per 13.3.1.2 para 8
    operator T*() const { return &value_; }
    mutable T value_;
    };

    который создается с помощью const std::pair<double, unsigned int>&; то компилятор жалуется на «формирование указателя на ссылочный тип: const std:: pair < double, unsigned int > &». Это внутренние, библиотечные обоснования. Для записи вот что я имею в своем коде:

    typedef uint32_t object_indentifier_t;
    typedef std::pair< double, object_identifier_t > object_tab_t;
    typedef boost::multi_array< object_tab_t, 2 > index_t;

    и вот использование, которое вызывает проблему:

    object_identifier const& center; // Actually a parameter
    index_t::const_subarray<1>::type::const_iterator pos_iterator_left = std::lower_bound( ix[i].begin(), ix[i].end(), sk[i], comparer );
    assert( pos_iterator_left -> second == center ); // <-- Error steams from here

    Здесь больше контекста ошибки:

    /opt/boost_1_48_0/include/boost/multi_array/iterator.hpp: In instantiation of 'struct boost::detail::multi_array::operator_arrow_proxy<const std::pair<double, unsigned int>&>':
    csrc/lsh_cpp/lsh.cpp|125 col 13| required from here
    /opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|40 col 10| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
    /opt/boost_1_48_0/include/boost/multi_array/iterator.hpp|43 col 7| error: forming pointer to reference type 'const std::pair<double, unsigned int>&'
    csrc/lsh_cpp/lsh.cpp: In member function 'lsh_cpp::neighbour_iterator_t lsh_cpp::lsh_t::pimpl_t::query(const object_identifier_t&) const':
    csrc/lsh_cpp/lsh.cpp|125 col 13| error: result of 'operator->()' yields non-pointer result

    ПРИМЕЧАНИЕ. Этот класс является частью boost:: multi_array (я уже писал это), и я не создаю его напрямую. Я написал выше своего экземпляра. Класс создается экземпляром boost:: multi_array следующим образом:

     operator_arrow_proxy<reference>
    operator->() const
    {
    return operator_arrow_proxy<reference>(this->dereference());
    }

    Использование «ссылки» заставляет меня думать, что ссылка предназначена. Есть ли причина, по которой обращение к ссылке не работает? Я думаю, помню, что сделал это сам пару раз и получал адрес оригинальной переменной с псевдонимом таким образом….

    Понравилась статья? Поделить с друзьями:

    Читайте также:

  • Error formerr resolving
  • Error network request failed перевод
  • Error former volume not mounted как исправить
  • Error network error occurred while attempting to read from the file
  • Error formatting volume ubuntu

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии