error C2259: 'ClassName' : cannot instantiate abstract class

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 46
Reputation: karang is an unknown quantity at this point 
Solved Threads: 0
karang karang is offline Offline
Light Poster

error C2259: 'ClassName' : cannot instantiate abstract class

 
0
  #1
Dec 10th, 2008
HI

I have a class className which is an abstract class. I am attaching the definition in the code snipet below.

when I am writing the line I am getting an error

error C2259: 'className' : cannot instantiate abstract class

From this error I have understood that we cannot create an instance of an abstract class

But when I make the object of the class i.e.
className obj.
and try to access the public function initState().

I am getting an error

"object reference is not set"

How to resolve this problem


  1.  
  2.  
  3. class ClassName : public Class2, public Class3{
  4. virtual ~ClassName{}
  5. public:
  6. virtual void initState ();
  7. protected:
  8. virtual void clearState ();
  9. }

Regards
Karan
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: error C2259: 'ClassName' : cannot instantiate abstract class

 
0
  #2
Dec 10th, 2008
Provide a small but complete example of code that exhibits your problem.

Your code sample and description is not complete, and the cause of the error is probably in something you haven't shown or described.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 46
Reputation: karang is an unknown quantity at this point 
Solved Threads: 0
karang karang is offline Offline
Light Poster

Re: error C2259: 'ClassName' : cannot instantiate abstract class

 
0
  #3
Dec 10th, 2008
Hi

I have a question regarding the abstract class.

If the class contains 5 pure virtual methods then it is necessary to implement all the methods of the class by the derived class.

Regards
Karan
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: error C2259: 'ClassName' : cannot instantiate abstract class

 
0
  #4
Dec 10th, 2008
It is necessary for the derived class to override all inherited pure virtual functions, otherwise the derived class remains an abstract class.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC