Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 c++ program: cannot instantiate abstract class

views
     
TSAthono
post Aug 7 2012, 02:18 AM, updated 14y ago

Getting Started
**
Junior Member
227 posts

Joined: Dec 2005
user posted image
This leads me to this page:
http://msdn.microsoft.com/query/dev10.quer...ORLIST)&rd=true
Compile Error C2259 is from a C++ program but the page calls the abstract class an "interface":

QUOTE
Whenever you derive from an interface and implement the interface methods in the derived class with access permissions other than public, you may receive C2259. This occurs because the compiler expects the interface methods implemented in the derived class to have public access. When you implement the member functions for an interface with more restrictive access permissions, the compiler does not consider them to be implementations for the interface methods defined in the interface, which in turn makes the derived class an abstract class.

There are two possible workarounds for the problem:

Make the access permissions public for the implemented methods.


Use the scope resolution operator for the interface methods implemented in the derived class to qualify the implemented method name with the name of the interface.
The bad news is that I have already made all of the methods public in the class:
CODE

class AmbientOccluder: public Light {
public:

 AmbientOccluder(void);

decypher
post Aug 7 2012, 04:41 AM

低头族
*****
Senior Member
864 posts

Joined: Apr 2006
From: Earth


QUOTE(Athono @ Aug 7 2012, 02:18 AM)
» Click to show Spoiler - click again to hide... «
Mind to give us a short and readable version of your code that reproduces the same error?
WongGei
post Aug 7 2012, 09:50 AM

Regular
******
Senior Member
1,206 posts

Joined: Dec 2007
From: Kuala Lumpur
Find the documentation for the Light class. May be there is a pure virtual function there that need implementation.

pure virtual function is something like this

void function() = 0;

You need to implement it in AmbientOccluder class to eliminate the error
TheSolver
post Aug 7 2012, 02:27 PM

Regular
******
Senior Member
1,108 posts

Joined: Jun 2011
QUOTE(Athono @ Aug 7 2012, 02:18 AM)
user posted image
This leads me to this page:
http://msdn.microsoft.com/query/dev10.quer...ORLIST)&rd=true
Compile Error C2259 is from a C++ program but the page calls the abstract class an "interface":
The bad news is that I have already made all of the methods public in the class:
CODE

class AmbientOccluder: public Light {
public:

 AmbientOccluder(void);

*
Isn't in C++, you need to call the constructor with the parentheses? I always call with empty parentheses even for one without args (void)?
dstl1128
post Aug 8 2012, 08:43 AM

Look at all my stars!!
*******
Senior Member
4,464 posts

Joined: Jan 2003
QUOTE(TheSolver @ Aug 7 2012, 02:27 PM)
Isn't in C++, you need to call the constructor with the parentheses? I always call with empty parentheses even for one without args (void)?
*
That's for Java.

 

Change to:
| Lo-Fi Version
0.0171sec    0.56    5 queries    GZIP Disabled
Time is now: 21st December 2025 - 07:17 AM