943,660 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 6331
  • C++ RSS
Dec 10th, 2008
0

error C2259: 'ClassName' : cannot instantiate abstract class

Expand Post »
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


C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Light Poster
karang is offline Offline
46 posts
since Jul 2008
Dec 10th, 2008
0

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

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.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008
Dec 10th, 2008
0

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

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
Reputation Points: 10
Solved Threads: 0
Light Poster
karang is offline Offline
46 posts
since Jul 2008
Dec 10th, 2008
0

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

It is necessary for the derived class to override all inherited pure virtual functions, otherwise the derived class remains an abstract class.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ card game war
Next Thread in C++ Forum Timeline: Reading from text file into array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC