Re: STL initialization of an abstract class


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by Daniel Longest on April 16, 2001 at 02:23:27:

In Reply to: STL initialization of an abstract class posted by Shereef on April 15, 2001 at 06:24:11:

If I copy your sample code and compile it (after providing an abstract base class called abstractPtr), I get no errors. BTW, the notion that constructors are inherited is incorrect. Constructors are not inherited, nor are destructors or the assignment operator. Look at the Virtual Constructior Idiom, the comp.lang.c++ talks about this, http://www.parashift.com/cpp-faq-lite/abcs.html#[22.5]

Daniel
: I'm having problems figuring out how to initialize my STL container for my abstract class. This is esentially what I have done:

: class Foo
: {
: private:
: std::list< abstractPtr* > myList;
: public:
: Foo() : myList(10) {}
: };

: I keep getting the error C2758: 'myList' : must be initialized in constructor base/member initializer list

: I thought that was what I had done above, but apparently it didn't solve the problem. Since the STL's store a copy of the objects, I have included a copy constructor for my abstract class so that should be inherited by my derived classes so I shouldn't have any problems, right? But I seem to missing something.
: Thanks.




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]