Click here to Skip to main content
16,006,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: vector.push_back, item disappears Pin
Anthony Mushrow9-Mar-08 15:18
professionalAnthony Mushrow9-Mar-08 15:18 
GeneralRe: vector.push_back, item disappears Pin
Mark Salsbery9-Mar-08 15:31
Mark Salsbery9-Mar-08 15:31 
QuestionThe old story of "DEBUG vs RELEASE" Pin
Joseph Marzbani9-Mar-08 5:55
Joseph Marzbani9-Mar-08 5:55 
QuestionRe: The old story of "DEBUG vs RELEASE" Pin
CPallini9-Mar-08 6:16
mveCPallini9-Mar-08 6:16 
GeneralRe: The old story of "DEBUG vs RELEASE" Pin
john56329-Mar-08 21:32
john56329-Mar-08 21:32 
GeneralCopy constructor problem [modified] Pin
followait9-Mar-08 5:48
followait9-Mar-08 5:48 
GeneralRe: Copy constructor problem Pin
CPallini9-Mar-08 5:58
mveCPallini9-Mar-08 5:58 
GeneralRe: Copy constructor problem Pin
Rajkumar R9-Mar-08 20:26
Rajkumar R9-Mar-08 20:26 
followait wrote:
Add a virtual function like clone()?


I guess you modified to add the above, and you want some other method to call the copy constructor.

I assume, if m_list contains Base and derived pointers means your list holds a single type may be "Base *. I assume your base class destructor is virtual destructor other wise you end up not calling derived class destructor if it is derived object and pointer is base.

If you have any virtual function, possibly atleast virtual destructor, then you can use the runtime type information to call the copy constructor,

Base *pObj = new Derived();
 Base *pObjClone = NULL;

 const type_info& typeInfo = typeid(*pObj);
 if (typeid(Derived) == typeInfo)
 {
     pObjClone  = new Derived(( Derived & )*pObj);
 }
 else if (typeid(Base) == typeInfo)
 {
     pObjClone  = new Base(( Base & )*pObj);
 }
 /*else if (typeid(...) == typeInfo)
 {
 }*/
 else
 {
     // invalid type
 }


Note: if you don't have virtual destructor, deleting the list item may have memory leak.

this method can be used if your class have any virtual function and you don't want to change the code to add clone() method.

if you don't have virtual functions and don't want to add clone method, may be storing type (enumerated values) along with the pointer in the list, or separte list for each type can be used.

if you are free to add virtual functions, Clone() method will be the right choice.
GeneralStandalone EXE Pin
ddspliting9-Mar-08 4:21
ddspliting9-Mar-08 4:21 
GeneralOh, they made it again! Pin
CPallini9-Mar-08 5:50
mveCPallini9-Mar-08 5:50 
GeneralRe: Standalone EXE Pin
followait9-Mar-08 5:51
followait9-Mar-08 5:51 
GeneralRe: Standalone EXE Pin
ddspliting9-Mar-08 10:12
ddspliting9-Mar-08 10:12 
GeneralRe: Standalone EXE Pin
CPallini9-Mar-08 11:18
mveCPallini9-Mar-08 11:18 
GeneralRe: Standalone EXE Pin
followait9-Mar-08 15:49
followait9-Mar-08 15:49 
GeneralRe: Standalone EXE Pin
ddspliting14-Mar-08 4:12
ddspliting14-Mar-08 4:12 
GeneralUnexpected linker fault Pin
Anthony Appleyard9-Mar-08 3:14
Anthony Appleyard9-Mar-08 3:14 
AnswerRe: Unexpected linker fault Pin
Rajkumar R9-Mar-08 3:38
Rajkumar R9-Mar-08 3:38 
GeneralRe: Unexpected linker fault Pin
CPallini9-Mar-08 3:41
mveCPallini9-Mar-08 3:41 
Generalunqualified name in template Pin
George_George9-Mar-08 3:07
George_George9-Mar-08 3:07 
GeneralDetailed .map file Pin
ForNow9-Mar-08 2:54
ForNow9-Mar-08 2:54 
GeneralRecord the number of command clicks on the main GUI Pin
Golden Lee9-Mar-08 1:47
Golden Lee9-Mar-08 1:47 
GeneralRe: Record the number of command clicks on the main GUI Pin
Rajkumar R9-Mar-08 3:08
Rajkumar R9-Mar-08 3:08 
QuestionDLL Plugins Pin
Ivan-bg9-Mar-08 1:18
Ivan-bg9-Mar-08 1:18 
GeneralRe: DLL Plugins Pin
CPallini9-Mar-08 3:48
mveCPallini9-Mar-08 3:48 
GeneralRe: DLL Plugins Pin
Ivan-bg9-Mar-08 4:50
Ivan-bg9-Mar-08 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.