U++ framework
Do not panic. Ask here before giving up.

Home » Community » Newbie corner » |SOLVED] Vector of object: cast to inherited class
Re: Vector of object: cast to inherited class [message #52370 is a reply to message #52368] Sun, 15 September 2019 17:31 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1432
Registered: December 2006
Ultimate Contributor
No problem.
A quiz for you.
Why the code below is working the way it is working (printing out "Hello from A" instead of "Hello from B")? Smile

struct A {
	virtual ~A() {
		Hello();
	}
	virtual void Hello() const {
		Cout() << "Hello from A" << EOL;
	}
};

struct B : A {
	void Hello() const {
		Cout() << "Hello from B" << EOL;
	}
};

CONSOLE_APP_MAIN
{
	Array<A> arrA;
	arrA.Create<B>();
}


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: copying code from web into IDE
Next Topic: Simple way to develope 2D Game
Goto Forum:
  


Current Time: Thu Jun 18 01:49:25 GMT+2 2026

Total time taken to generate the page: 0.00542 seconds