Page 1 of 1

How to make a derived class?

Posted: Mon Feb 28, 2005 6:18 pm
by CZestmyr
Hi, I'm still just playing around with Irrlicht and trying different things. I wanted to make a simple model of a solar system and I wanted to create my own IPlanetSceneNode for this, which would be derived from the IAnimatedMeshSceneNode class. The new class would contain data like mass of the planet, acceleration and movement data etc. But I can't compile the app, cause the compiler prints something like this:

In function `int main()':
cannot allocate an object of type `IPlanetSceneNode'
because the following virtual functions are abstract:
...Followed by a list of functions from the original IAnimatedSceneNode...

Please help me compile this little piece of crap.

I know, that this is probably due to my lack of knowledge in C++, but after all, this is a beginner forum :)

Let me know, if you need to see the code, I just wanted to keep the thread compact.

Posted: Mon Feb 28, 2005 6:49 pm
by bal
I checked the source of IAnimatedMeshSceneNode and it was exactly like I thought it was :P.
The file is an interface, an abstract class. It contains several virtual functions that are followed by a " = 0;" which mean they are there for defining the interface (the layout of the class) but they aren't declared. Why? Because several other classes inherit from IAnimatedMeshSceneNode and they do share the same function names but the implementation of the function is totally different in each one (different file-formats etc). So in short, an abstract class or interface (guess where the "I" comes from) like IAnimatedMeshSceneNode is a class that hasn't got any real use, it just defines a global interface to fit in the OO-design of a project. Then you get those nice visual schemes with them arrows and all :P.

Now then, enough theory. Why are you getting that error? Because such funtions (with the " = 0;") need to be defined in the derived class. How can you fix this? Copy the implementation code from e.g. CAnimatedMeshSceneNode for all the abstract functions in IAnimatedMeshSceneNode to your own IPlanetSceneNode implementation so they are defined.

Well, this must be some of my longest posts (still can't beat vermeer though). Hope you understood this tiny bit of C++ theory. Else I recommend you the free Thinking in C++ books.

Posted: Mon Feb 28, 2005 7:57 pm
by cartoonit
Going off topic, but Bal, that amount of typing, you must be tired??? :lol: :lol:

Posted: Mon Feb 28, 2005 8:06 pm
by bal
cartoonit wrote:Going off topic, but Bal, that amount of typing, you must be tired??? :lol: :lol:
Bwa, looking at it now it isn't that long indeed *g*. But it took some time to think how I could explain something I understand in clear language to someone who doesn't know a lot of it appereantly (no offense of course :wink:).

Posted: Mon Feb 28, 2005 8:11 pm
by cartoonit
I don't think you will ever catch vemeer!!!! :lol: :lol:

Posted: Tue Mar 01, 2005 7:48 pm
by CZestmyr
bal wrote:
cartoonit wrote:Going off topic, but Bal, that amount of typing, you must be tired??? :lol: :lol:
Bwa, looking at it now it isn't that long indeed *g*. But it took some time to think how I could explain something I understand in clear language to someone who doesn't know a lot of it appereantly (no offense of course :wink:).
Thanks a lot. BTW. I didn't take it as offence, I know that I'm beginner. :wink: