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

Home » Community » Newbie corner » |SOLVED] Vector of object: cast to inherited class
|SOLVED] Vector of object: cast to inherited class [message #52353] Fri, 13 September 2019 16:32 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello,

Is it possible to do something like that :

#include <Core/Core.h>

using namespace Upp;

class A : public Moveable<A>{
	public:
	A(){}
	virtual void Hello(){
		Cout() << "Hello from A" <<"\n";
	}	
};

class B :public A, public Moveable<B>{
	public:
	B(){}
	void Hello(){
		Cout() << "Hello from B" <<"\n";
	}	
};

CONSOLE_APP_MAIN
{
	Vector<A> myVector;
	
	static_cast<B&>(myVector.Add()).Hello();
	//Looking for "Hello from B"
}


Without using Vector of ptr or reference ?

Thanks in advance
Best regard.

[Updated on: Sun, 15 September 2019 12:53]

Report message to a moderator

 
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: Mon Jun 15 07:25:36 GMT+2 2026

Total time taken to generate the page: 0.00709 seconds