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'
--------------------
Expand|Select|Wrap|Line Numbers
- #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<intvi;
- Foo foo = Foo (vi);
- return 0;
- }
thanks in advance,
George