954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error C2259: 'ClassName' : cannot instantiate abstract class

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

class ClassName : public Class2, public Class3{	
	virtual ~ClassName{}		
public:
	virtual void initState ();
protected:
	virtual void clearState ();
}


Regards
Karan

karang
Light Poster
46 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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.

grumpier
Posting Whiz in Training
211 posts since Aug 2008
Reputation Points: 193
Solved Threads: 32
 

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

karang
Light Poster
46 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

It is necessary for the derived class to override all inherited pure virtual functions, otherwise the derived class remains an abstract class.

grumpier
Posting Whiz in Training
211 posts since Aug 2008
Reputation Points: 193
Solved Threads: 32
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You