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 » U++ Library support » U++ Widgets - General questions or Mixed problems » why no 'Ctrl* Ctrl::Clone() const = 0' (virtual constructor)
Re: why no 'Ctrl* Ctrl::Clone() const = 0' (virtual constructor) [message #28653 is a reply to message #28381] Thu, 09 September 2010 10:56 Go to previous messageGo to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i tried it with the following approach, it works in MSC9 but crashed in TDMGCC, any idea why? (maybe the brute cast is inapropriate..alignment of vtable wrong or sth..)

//copyable interface, implementing the Copy function, used by PolyDeepCopyNew
template<class T, class B = EmptyClass>
class Copyable : public B
{
public:
	virtual ~Copyable() {}
	virtual T* Copy() const { return new T(); }
};

//this is a nice helper, meant to be used like i.e. PolyCopying<EditCtrl>
//assigning Copy'ed instances to PolyCopying<Ctrl>* with a cast, as Ctrl is direct base class of EditCtrl
template<class T>
class PolyCopying : public Copyable< PolyCopying<T>, PolyDeepCopyNew<PolyCopying<T>, T> > {};

////

	PolyCopying<EditInt> abc;
	PolyCopying<Ctrl>* pabc = (PolyCopying<Ctrl>*)abc.Copy();
	PolyCopying<Ctrl>* pabc2 = pabc->Copy();

	Add(pabc2->HSizePos().TopPos(0,100)); //crashes here
	delete pabc2;


thats basicly why i need to have the Copy function in Ctrl..it makes factory cloning easy..

[Updated on: Thu, 09 September 2010 11:02]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Dockable toolbars
Next Topic: ColumnList RefreshCursor public
Goto Forum:
  


Current Time: Mon May 13 11:36:22 CEST 2024

Total time taken to generate the page: 0.03621 seconds