Click here to Skip to main content
15,900,254 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: EXCEL.EXE is not getting killed Pin
David Crow4-Dec-09 3:33
David Crow4-Dec-09 3:33 
GeneralRe: EXCEL.EXE is not getting killed Pin
T21024-Dec-09 3:57
T21024-Dec-09 3:57 
GeneralRe: EXCEL.EXE is not getting killed Pin
David Crow4-Dec-09 4:02
David Crow4-Dec-09 4:02 
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 
There's no difference concerning this behavior between a copy constructor and an assignement operator, so my explanation is valid for both.

The problem with a default constructor is that it simply copies byte by byte all the content of your class. This is ok for most of the cases when your class contains only plain data type for instance.

Now, if you have a class which contains a pointer and then if you copy your class using a shalow copy, both class instances will contain a pointer pointing at the same memory location. If you have a destructor like this:

MyClass::~MyClass() 
{
  if (myPointer) 
  {
    delete myPointer;
    myPointer = NULL;
  }
}


Then you will end up in big troubles once one of the class instances gets destroyed because its destructor will be called and you will end up with a pointer pointing to memory which has been release in your other instance.

So, what you have to do instead is allocate a new pointer and copy the content when you copy the class:

MyClass::MyClass(const MyClass& copy)
{
  myPointer = new ....;  // Allocate a new pointer
  // Copy the content of the pointer based on what is in "copy"
  ......
}


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: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 
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 

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.