Jump to content

Virtual functions calls don't always go to the child-most class


photo

Recommended Posts

In an example I have 3 classes set up like this 

class Parent
{
	virtual void MainFunction()
	{
		log.message( "Parents MainFnction\n" );
	}

	virtual void NextFunction()
	{
		log.message( "Parents NextFnction\n" );
	}
};

class Child : Parent
{
	virtual void MainFunction()
	{
		log.message( "Child MainFunction\n" );

		NextFunction();
	}

};

class GrandChild : Child
{
	virtual void NextFunction()
	{
		log.message( "GrandChild NextFnction\n" );
	}
};

If I create a GrandChild object and call MainFunction

GrandChild gc = new GrandChild();
gc.NextFunction();

I would Expect the Child's version of MainFunction to get called which in turn should call the GrandChilds Version of NextFunction, but instead in Unigine Script The output is...

 

Child MainFunction

Parent NextFunction

 

For some reason the child-most class isn't getting called.  If I do the same thing in C++ I get what I expect to happen the Child MainFunction calls the NextFunction in the GrandChild Class.

Link to comment
×
×
  • Create New...