No default constructor?

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
DataCable
Posts: 5
Joined: Sat Jan 07, 2006 6:51 am

No default constructor?

Post by DataCable »

I'm trying to create a sub-class of CTriangleSelector which will create an array of my own triangle3df sub-class. Essentially, all I'm doing (so far) is overriding the (IMesh* mesh, ISceneNode* node) constructor. However, when I try to compile, I get this error:

no matching function for call to `irr::scene::CTriangleSelector::CTriangleSelector()'

It sounds like it's complaining that I'm trying to call the nonexistant default constructor of CTriangleSelector, which I'm not (deliberately, anyway). So why does my sub-class need a default constructor from its super when CTriangleSelector doesn't need one from ITriangleSelector? I'm stumped. :?
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Post some more code around the problem area. Are you using new with your overridden class? Or are you declaring it as a member of something? If so, you need to use the proper contructor
DataCable
Posts: 5
Joined: Sat Jan 07, 2006 6:51 am

Post by DataCable »

Well, this alone will produce that error:

Code: Select all

#include <CTriangleSelector.h>
#include <IMesh.h>
#include <ISceneNode.h>

class UVTriangleSelector : public CTriangleSelector
{
  public:
	UVTriangleSelector( IMesh* mesh, ISceneNode* node ) {};
};
I have an implimentation for the above constructor, but the content seems to be irrelevant. This empty implimentation gives the same result.

It occurred to me that CTriangleSelector contains 2 data members (protected, if that's relevant) whereas ITriangleSelector only has accessor functions. Could that have anything to do with it?
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

DataCable wrote:Well, this alone will produce that error:

Code: Select all

#include <CTriangleSelector.h>
#include <IMesh.h>
#include <ISceneNode.h>

class UVTriangleSelector : public CTriangleSelector
{
  public:
	UVTriangleSelector( IMesh* mesh, ISceneNode* node ) {};
};
I have an implimentation for the above constructor, but the content seems to be irrelevant. This empty implimentation gives the same result.

It occurred to me that CTriangleSelector contains 2 data members (protected, if that's relevant) whereas ITriangleSelector only has accessor functions. Could that have anything to do with it?
Your problem is two-fold:

When the derived class is constructed, the base class's constructor is also called. Since there is no CTriangleSelector(void) constructor, the compiler doesn't know what to pass into the bass class's constructor.

This will make the compilation error go away:

Code: Select all


class UVTriangleSelector : public CTriangleSelector
{
  public:
	UVTriangleSelector( IMesh* mesh, ISceneNode* node ) : CTriangleSelector(mesh, node) {}
};

You have to use the ' : variable(value) ' syntax and initialize the base class's constructor.


That's probably not what you want, however. You probably want

Code: Select all


class UVTriangleSelector : public ITriangleSelector
{
  public:
	UVTriangleSelector( IMesh* mesh, ISceneNode* node ) {}
};

The engine exports ITriangleSelector, not CTriangleSelector. You should not use the engine's internal classes! :)

You should never be able to do '#include <CTriangleSelector.h>' and have the compiler actually find the file. Why is the irrlicht source directory in your include path? :)
DataCable
Posts: 5
Joined: Sat Jan 07, 2006 6:51 am

Post by DataCable »

zenaku wrote: When the derived class is constructed, the base class's constructor is also called. Since there is no CTriangleSelector(void) constructor, the compiler doesn't know what to pass into the bass class's constructor.
Pretty much what I had figured, but that's what's confusing me. ITriangleSelector doesn't have a (void) constructor either, yet CTriangleSelector obviously compiles just fine.
This will make the compilation error go away:
[...]
That's probably not what you want, however.
Indeed, since that's just calling the constructor function I want to override in the first place.
You probably want [...]
Well, that's what I ended up doing as a stop-gap measure, which apparently will be permenant. What I was hoping to do is write a class that inherits from CTriangleSelector and differs only in the implimentation of that particular constructor, so that I wouldn't have to re-write (that is, copy/paste :lol: ) the rest of CTriangleSelector's code in my own class.

However, CTriangleSelector is fairly "light", and I'm already re-writing the longest single function in it anyway, so copying the rest isn't too terribly inefficient.
Why is the irrlicht source directory in your include path? :)
Because I put it there. :mrgreen:
Post Reply