Click here to Skip to main content
16,004,906 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: OnDraw() troubles.... Pin
bitpusher23-Feb-05 6:40
bitpusher23-Feb-05 6:40 
GeneralRe: OnDraw() troubles.... Pin
bobi_zcl22-Feb-05 21:50
bobi_zcl22-Feb-05 21:50 
GeneralRe: OnDraw() troubles.... Pin
bitpusher23-Feb-05 6:36
bitpusher23-Feb-05 6:36 
GeneralSTL sort functor question Pin
Maximilien22-Feb-05 10:03
Maximilien22-Feb-05 10:03 
GeneralRe: STL sort functor question Pin
Gevorg22-Feb-05 10:09
Gevorg22-Feb-05 10:09 
GeneralRe: STL sort functor question Pin
Michael Dunn22-Feb-05 11:11
sitebuilderMichael Dunn22-Feb-05 11:11 
GeneralQuestion about the copy constructor Pin
Budric B.22-Feb-05 9:00
Budric B.22-Feb-05 9:00 
GeneralRe: Question about the copy constructor Pin
Mohammad A Gdeisat22-Feb-05 10:09
Mohammad A Gdeisat22-Feb-05 10:09 
Hi friend,

I don't know what kind of book you read, but i think that you might missunderdstood the issue.

In the example you wrote:
a = SomeFunction(); //returns MyClass object

You are right, the operator= is called, but have you read the implementation of operator=...?

if you are using a default version of operator=, then you will get a call of the copy construcor because its implemntation goes like this:
<br />
M operator=(const M &m)<br />
{<br />
    return m;     //return m by value, not by reference nor by pointer<br />
}

because a copy of object m is returned BY VALUE, not the actual object will be returned, but a copy of object m. No memory leak will occur because this temporary object is created on the stack!

Furthermore, if you create an object with the operator=, the copy constructor will be called instaed of operator=

MyClass new=old; //copy constructor is called.

A good resource is the book Thinking in C++ version 2, it is available on many sites for FREE. use a search engine to find it.

Good luck,
Mohammad Gdeisat
GeneralRe: Question about the copy constructor Pin
S. Senthil Kumar22-Feb-05 18:19
S. Senthil Kumar22-Feb-05 18:19 
GeneralRe: Question about the copy constructor Pin
Anonymous22-Feb-05 21:55
Anonymous22-Feb-05 21:55 
GeneralRe: Question about the copy constructor Pin
S. Senthil Kumar22-Feb-05 18:35
S. Senthil Kumar22-Feb-05 18:35 
GeneralRe: Question about the copy constructor Pin
John R. Shaw22-Feb-05 18:58
John R. Shaw22-Feb-05 18:58 
GeneralThank you all Pin
Budric B.23-Feb-05 3:05
Budric B.23-Feb-05 3:05 
GeneralDebuggin mixed (managed/unmanaged) code Pin
CLermen22-Feb-05 8:44
CLermen22-Feb-05 8:44 
GeneralRe: Debuggin mixed (managed/unmanaged) code Pin
Sheng Jiang 蒋晟22-Feb-05 13:25
Sheng Jiang 蒋晟22-Feb-05 13:25 
GeneralRe: Debuggin mixed (managed/unmanaged) code Pin
CLermen23-Feb-05 2:31
CLermen23-Feb-05 2:31 
QuestionCFormView window can never be on top of CDialog. Why? How can I change this? Pin
digwizfox22-Feb-05 8:10
digwizfox22-Feb-05 8:10 
GeneralNamedPipe Server Pin
humps22-Feb-05 7:50
humps22-Feb-05 7:50 
GeneralImplementing a join operation in an ODBC based application -- Question! Pin
ur_unholyness22-Feb-05 6:10
ur_unholyness22-Feb-05 6:10 
GeneralRe: Implementing a join operation in an ODBC based application -- Question! Pin
David Crow22-Feb-05 8:17
David Crow22-Feb-05 8:17 
GeneralRe: Implementing a join operation in an ODBC based application -- Question! Pin
ur_unholyness23-Feb-05 6:58
ur_unholyness23-Feb-05 6:58 
GeneralRe: Implementing a join operation in an ODBC based application -- Question! Pin
David Crow23-Feb-05 7:23
David Crow23-Feb-05 7:23 
GeneralQueryPerformance Pin
wallacej22-Feb-05 6:03
wallacej22-Feb-05 6:03 
GeneralRe: QueryPerformance Pin
Michael Dunn22-Feb-05 7:38
sitebuilderMichael Dunn22-Feb-05 7:38 
QuestionPlace control next to scrollbar? Pin
ehh22-Feb-05 4:27
ehh22-Feb-05 4:27 

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.