Created
July 15, 2011 07:39
-
-
Save sebastiangeiger/1084255 to your computer and use it in GitHub Desktop.
non-static reference member 'A& B::myA', can't use default assignment operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class A; //Forward declaration | |
class B{ | |
public: | |
B(string name, A& a):myA(a), name(name){ | |
cout << "Works with pointer" << endl; | |
}; | |
private: | |
A& myA; | |
string name; | |
}; | |
class A{ | |
public: | |
A(){ | |
cout << "Constructing A" << endl; | |
if(bs.empty()) cout << "Vector is empty" << endl; | |
bs.push_back(B("First", *this)); | |
cout << "Array has " << bs.size() << " elements." << endl; | |
}; | |
private: | |
std::vector<B> bs; | |
}; | |
int main() { | |
cout << "Start" << endl; | |
A a; | |
cout << "Ok." << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make all
Building file: ../src/ConstructorExample.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ConstructorExample.d" -MT"src/ConstructorExample.d" -o "src/ConstructorExample.o" "../src/ConstructorExample.cpp"
../src/ConstructorExample.cpp: In member function 'B& B::operator=(const B&)':
../src/ConstructorExample.cpp:7: instantiated from 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = B, _Alloc = std::allocator]'
/usr/include/c++/4.2.1/bits/stl_vector.h:608: instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = B, _Alloc = std::allocator]'
../src/ConstructorExample.cpp:23: instantiated from here
../src/ConstructorExample.cpp:7: error: non-static reference member 'A& B::myA', can't use default assignment operator
/usr/include/c++/4.2.1/bits/vector.tcc: In member function 'void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = B, _Alloc = std::allocator]':
/usr/include/c++/4.2.1/bits/stl_vector.h:608: instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = B, _Alloc = std::allocator]'
../src/ConstructorExample.cpp:23: instantiated from here
/usr/include/c++/4.2.1/bits/vector.tcc:256: note: synthesized method 'B& B::operator=(const B&)' first required here
make: *** [src/ConstructorExample.o] Error 1
**** Build Finished ****