pointer to abstract class

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
chaoslion
Posts: 25
Joined: Sun Oct 30, 2005 1:44 pm

pointer to abstract class

Post by chaoslion »

Hey guys

i wanted to create an gui-env independent gui element so that i can choose
when it should be drawn or not, through the ->draw() function.
So i have created a pointer:

Code: Select all

gui::IGUIButton*btn;
and then the creation, which actually fails because he says
"cannot instantiate abstract class"

Code: Select all

btn = new gui::IGUIButton
where is the exact problem??
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

The problem is, as the error message says, that the compiler can't (of course) create an instance of an abstract class because an abstract class doesn't have any implementation but just the interface. So the compiler can't create any code from it. ;)

You have to use the class which implements the abstract class interface. So you should use

Code: Select all

btn = guiEnv->addButton(...);
instead.

Regards - Xaron
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

i have the similar problem.and i solved it.see my post at
begginers help/ABSTRACT CLASS ERROR
Post Reply