How to make a derived class?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
CZestmyr
Posts: 72
Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:

How to make a derived class?

Post 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.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post 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.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
cartoonit
Posts: 286
Joined: Mon Nov 15, 2004 6:36 pm

Post by cartoonit »

Going off topic, but Bal, that amount of typing, you must be tired??? :lol: :lol:
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post 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:).
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
cartoonit
Posts: 286
Joined: Mon Nov 15, 2004 6:36 pm

Post by cartoonit »

I don't think you will ever catch vemeer!!!! :lol: :lol:
CZestmyr
Posts: 72
Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:

Post 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:
Post Reply