Jump to content

Call methods from base class


photo

Recommended Posts

Posted

I have two classes:

 

class BaseObject
{
	private:
		Node node;
		string name;
	public:
		void init(Node node, string name = "")
		{
			this.node = node;
			this.name = name;

			log.message("BaseObject::init()\n");
		}

		string getName()
		{
			return name;
		}

		Node getNode()
		{
			return node;
		}

		void setName(string value)
		{
			name = value;
		}

		void setNode(Node value)
		{
			node = value;
		}

		void shutdown()
		{

		}

		void update()
		{

		}
};

class SwitchObject : BaseObject
{
	public:
		void init(Node node)
		{
			BaseObject::init(node);

			log.message("SwitchObject::init()\n");
		}

		void shutdown()
		{
			BaseObject::shutdown();
		}

		void update()
		{
			BaseObject::update();
		}
};

 

If I do next:

SwitchObject object = new SwitchObject();
object.init(someNode);

all good, I see trace:

BaseObject::init()

SwitchObject::init()

 

If I do next:

BaseObject object = new SwitchObject();
object.init(someNode);

I see trace:

BaseObject::init()

It's not correct

Posted

you're requesting a virtual function feature in script engine.

 

I think that's not posible nor easy task for a script engine.

Posted

I have two classes:

 

All functions are treated as virtual.

Try use same signatures for init function.

init(Node node, string name = "") and init(Node node) is different functions from script point of view.

Posted

All functions are treated as virtual.

Try use same signatures for init function.

init(Node node, string name = "") and init(Node node) is different functions from script point of view.

I see, thanks

Posted

you're requesting a virtual function feature in script engine.

 

I think that's not posible nor easy task for a script engine.

You are developing very powerful system: beautiful render, excellent cross-platform engine and internal script, that allow abstract from specific platform - IMHO, you should little by little upgrade you script OOP features - it will be amazing for developing :)

Posted

well, my mistake :) , I didn't notice you are using different parameters, so these different parameter make these two function as normal member function. So what you get is correct result.

 

Actually I use OOP everyday :)

×
×
  • Create New...