Click here to Skip to main content
15,918,333 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Embedding data in exe's Pin
Xzyx987X8-Jul-05 16:14
Xzyx987X8-Jul-05 16:14 
GeneralRe: Embedding data in exe's Pin
John R. Shaw8-Jul-05 16:46
John R. Shaw8-Jul-05 16:46 
GeneralRe: Embedding data in exe's Pin
Xzyx987X8-Jul-05 17:07
Xzyx987X8-Jul-05 17:07 
GeneralRe: Embedding data in exe's Pin
John R. Shaw8-Jul-05 18:33
John R. Shaw8-Jul-05 18:33 
GeneralRe: Embedding data in exe's Pin
David Crow8-Jul-05 16:36
David Crow8-Jul-05 16:36 
GeneralRe: Embedding data in exe's Pin
Xzyx987X8-Jul-05 17:09
Xzyx987X8-Jul-05 17:09 
Generalhelp: C++ copy constructors Pin
heskel8-Jul-05 15:04
heskel8-Jul-05 15:04 
GeneralRe: help: C++ copy constructors Pin
John R. Shaw8-Jul-05 16:01
John R. Shaw8-Jul-05 16:01 
myclass m1 = m2; // implicit call to copy constructor
myclass m1(m2); // explicit call to copy constructor

m1 = m2; // explicit call to operator=
m1(m2); // error if tried here

The compiler will generate a bitwise version of the copy constructor it you do not define your own version. This is ok as long as you class, and its data types, does not contain in allocated data pointers. If they contain data pointers, then you'll have two classes pointing to the data and when one of the class is destoyed the data pointed to is destoyed. What that means, is the data pointer in the class that still exist is now invalid and anything you try to do with it (including freeing it) it will cause problems (probably crash your program). Therefore, you need to create your own copy constructor that allocates memory for its self so you can make a copy of the stored data.

Note what I just said about copy constructors also applies to operator=, except that if you supply a copy constructor and you don't supply an operator=, then the compiler should generate an operator= that uses your copy constructor (instead of a bitwise copy). Therefore, if you supply a copy constructor, you should not need to supply your own operator=.

That should give you a good start at understanding why copy constructors are important. After all, whether you supply your own or the compiler generates one, there is going to be a copy constructor.

INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
Generalhelp:update_command_ui Pin
happycpp8-Jul-05 13:33
happycpp8-Jul-05 13:33 
GeneralRe: help:update_command_ui Pin
Jose Lamas Rios10-Jul-05 18:07
Jose Lamas Rios10-Jul-05 18:07 
GeneralC++ Copy constructors Pin
heskel8-Jul-05 13:02
heskel8-Jul-05 13:02 
GeneralRe: C++ Copy constructors Pin
Kevin McFarlane8-Jul-05 13:07
Kevin McFarlane8-Jul-05 13:07 
GeneralRe: C++ Copy constructors Pin
heskel8-Jul-05 13:12
heskel8-Jul-05 13:12 
GeneralRe: C++ Copy constructors Pin
Nemanja Trifunovic8-Jul-05 14:06
Nemanja Trifunovic8-Jul-05 14:06 
Generalwin32 threads Pin
Ann668-Jul-05 12:20
sussAnn668-Jul-05 12:20 
GeneralRe: win32 threads Pin
Blake V. Miller8-Jul-05 16:29
Blake V. Miller8-Jul-05 16:29 
Generalto IE programmers Pin
llp00na8-Jul-05 8:08
llp00na8-Jul-05 8:08 
GeneralRe: to IE programmers Pin
Jose Lamas Rios8-Jul-05 10:47
Jose Lamas Rios8-Jul-05 10:47 
GeneralRe: to IE programmers Pin
Ravi Bhavnani8-Jul-05 11:40
professionalRavi Bhavnani8-Jul-05 11:40 
GeneralRe: to IE programmers Pin
ThatsAlok8-Jul-05 21:21
ThatsAlok8-Jul-05 21:21 
GeneralHelp with LookupAccountSid Pin
Dimitris Vikeloudas8-Jul-05 5:54
Dimitris Vikeloudas8-Jul-05 5:54 
GeneralRe: Help with LookupAccountSid Pin
David Crow8-Jul-05 6:07
David Crow8-Jul-05 6:07 
GeneralRe: Help with LookupAccountSid..still looking Pin
Dimitris Vikeloudas8-Jul-05 6:22
Dimitris Vikeloudas8-Jul-05 6:22 
GeneralRe: Help with LookupAccountSid..still looking Pin
David Crow8-Jul-05 8:11
David Crow8-Jul-05 8:11 
GeneralUnderstanding Debug Information Displayed Pin
jerry1211a8-Jul-05 5:28
jerry1211a8-Jul-05 5:28 

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.