Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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: Fri Mar 29 12:20:45 CET 2024

Total time taken to generate the page: 0.01069 seconds