Click here to Skip to main content
15,906,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: EXCEL.EXE is not getting killed Pin
T21024-Dec-09 12:40
T21024-Dec-09 12:40 
GeneralRe: EXCEL.EXE is not getting killed Pin
David Crow5-Dec-09 5:40
David Crow5-Dec-09 5:40 
GeneralRe: EXCEL.EXE is not getting killed Pin
KTTransfer6-Dec-09 21:01
KTTransfer6-Dec-09 21:01 
QuestionDeep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
hrishiS3-Dec-09 22:27
hrishiS3-Dec-09 22:27 
AnswerRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
Cedric Moonen3-Dec-09 22:55
Cedric Moonen3-Dec-09 22:55 
GeneralRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
hrishiS3-Dec-09 23:02
hrishiS3-Dec-09 23:02 
AnswerRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
Rajesh R Subramanian3-Dec-09 23:12
professionalRajesh R Subramanian3-Dec-09 23:12 
GeneralRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
Cedric Moonen3-Dec-09 23:13
Cedric Moonen3-Dec-09 23:13 
hrishiS wrote:
What does the code of default constrictor is...what I mean is what is the code present in the default constructor?


If you don't provide any constructor yourself, the default constructor will simply assign all variables, similarly as you would do something like this:
MyClass::MyClass(const MyClass& copy)
{
   member1 = copy.member1;
   member2 = copy.member2;
   ....
}


So, it means that if your class contains a pointer, this will result in something like this:

MyClass::MyClass(const MyClass& copy)
{
   myPointer = copy.myPointer;
}


And of course this is not nice because both of your instances will have a pointer pointing at the same location and there's no way anymore to know which of the two has ownership of the pointer (so, which one is responsible for deleting it). And if you destroy that pointer in the class destructor, then you end up with the problem I described earlier: one instance will end up with a pointer pointing to memory which has been released (and thus which can contain corrupted data).

Furthermore, you can also encounter another problem than with the one you have when manipulating pointers. If one (or more) member of your class is an object that cannot be copied (because its copy constructor has been made private for instance), then your code won't even compile because there's no way for the default constructor of your class to copy the object (as the copy constructor is private). Thus, the only way to be able to copy your class is to provide a copy constructor that instead of calling the copy constuctor of your member, it will create an new instance of this member and initialize it properly.


hrishiS wrote:
Could you please elaborate this, what exactly is meant by copying using shallow copy? Does this mean copying with the default copy constructor what we have?


It is assigning all members from one class to another as I described at the begining of this message.

Cédric Moonen
Software developer

Charting control [v2.0]
OpenGL game tutorial in C++

GeneralRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
hrishiS3-Dec-09 23:59
hrishiS3-Dec-09 23:59 
GeneralRe: Deep copy and Shallow copy w.r.t Copy Constructor and Assignment Operator Pin
Cedric Moonen4-Dec-09 0:12
Cedric Moonen4-Dec-09 0:12 
QuestionHow can I close an CChildFrame within CHtmlView ? [modified] Pin
mesajflaviu3-Dec-09 22:14
mesajflaviu3-Dec-09 22:14 
Questionmulti-processes's memory sharing problem? Pin
nenfa3-Dec-09 19:45
nenfa3-Dec-09 19:45 
QuestionRe: multi-processes's memory sharing problem? Pin
norish3-Dec-09 22:12
norish3-Dec-09 22:12 
AnswerRe: multi-processes's memory sharing problem? Pin
Michael Schubert4-Dec-09 5:25
Michael Schubert4-Dec-09 5:25 
GeneralRe: multi-processes's memory sharing problem? Pin
nenfa7-Dec-09 20:08
nenfa7-Dec-09 20:08 
QuestionAccessing Dialog member Variable problem Pin
kamalilam3-Dec-09 19:30
kamalilam3-Dec-09 19:30 
AnswerRe: Accessing Dialog member Variable problem Pin
«_Superman_»3-Dec-09 19:40
professional«_Superman_»3-Dec-09 19:40 
AnswerRe: Accessing Dialog member Variable problem Pin
Madhu Nair3-Dec-09 19:44
Madhu Nair3-Dec-09 19:44 
AnswerRe: Accessing Dialog member Variable problem Pin
Cedric Moonen3-Dec-09 20:10
Cedric Moonen3-Dec-09 20:10 
AnswerRe: Accessing Dialog member Variable problem Pin
Rajesh R Subramanian3-Dec-09 21:14
professionalRajesh R Subramanian3-Dec-09 21:14 
QuestionWhich window has the focus [modified] Pin
SujayG3-Dec-09 18:17
SujayG3-Dec-09 18:17 
AnswerRe: Which window has the focus Pin
«_Superman_»3-Dec-09 18:21
professional«_Superman_»3-Dec-09 18:21 
GeneralRe: Which window has the focus Pin
SujayG3-Dec-09 18:31
SujayG3-Dec-09 18:31 
GeneralRe: Which window has the focus [modified] Pin
Madhu Nair3-Dec-09 19:28
Madhu Nair3-Dec-09 19:28 
AnswerRe: Which window has the focus Pin
vasu_sri3-Dec-09 20:18
vasu_sri3-Dec-09 20:18 

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.