Topic: Why isn't this legal C++


Author: "Michael H. Cox" <mhcox@earthling.net>
Date: 1998/04/21
Raw View
The following snippet of code gets the syntax error:

error C2614: 'list<class Foo,class std::allocator<class Foo>>' : illegal
member initialization: 'foos' is not a base or member

This code used to compile under 4.2.  Have they changed something in the
standard that makes this illegal?  Note that if you put the new expression
inside the body of the constructor or if you new an array of Foos (and
comment out the line above) all is OK.

#include <list>

class Foo
{
};

class Bar
{
 std::list<Foo> *foos;
 Foo *foos2;
public:
 Bar():
  foos(new std::list<Foo>), // error C2614
  foos2(new Foo[4])   // works fine if you comment above line out
 {}
};

Is this a compiler bug or am I doing something that is now illegal?
Any idea what's going on, please send mail to
mhcox@lucent.com

Thanks,
Mike Cox



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]