Hello everyone,
Why the below code segment will result in compile error? When I change code to the comment one (constructor), it can compile. The compiler is too stupid? :-)
I am using Visual Studio 2005.
--------------------
main.cpp(13) : error C2758: 'Foo::vi' : must be initialized in constructor base/member initializer list
see declaration of 'Foo::vi'
--------------------
Code:#include <vector> using namespace std; class Foo { private: vector<int>& vi; public: Foo (vector<int>& vi_in) { vi = vi_in; } /* Foo (vector<int>& vi_in) : vi (vi_in) { } */ }; int main() { vector<int> vi; Foo foo = Foo (vi); return 0; }
thanks in advance,
George



LinkBack URL
About LinkBacks



