Click here to Skip to main content
16,005,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Cache hit rates Pin
Randor 15-Jul-07 0:37
professional Randor 15-Jul-07 0:37 
QuestionObject return by value Pin
tom groezer14-Jul-07 9:30
tom groezer14-Jul-07 9:30 
AnswerRe: Object return by value Pin
DevMentor.org14-Jul-07 10:04
DevMentor.org14-Jul-07 10:04 
GeneralRe: Object return by value Pin
tom groezer14-Jul-07 13:54
tom groezer14-Jul-07 13:54 
GeneralRe: Object return by value Pin
DevMentor.org14-Jul-07 16:37
DevMentor.org14-Jul-07 16:37 
GeneralRe: Object return by value Pin
Mark Salsbery14-Jul-07 16:43
Mark Salsbery14-Jul-07 16:43 
GeneralRe: Object return by value Pin
tom groezer14-Jul-07 21:12
tom groezer14-Jul-07 21:12 
GeneralRe: Object return by value Pin
Mark Salsbery14-Jul-07 21:29
Mark Salsbery14-Jul-07 21:29 
I use 4 objects, all are on the stack. No objects are heap allocated.

tom groezer wrote:
Will it be correct if I retruned the same way from other functions of a class or is it that we could this only in assignment and copy constructor.


The same scoping and memory management rules apply as anywhere. It's up to us as programmers to
keep track of that.

Returning a reference or pointer to an automatic (stack) variable isn't going to work if the
caller tries to use it. The object has gone out of scope so it doesn't exist.

Any objects created in a function and returned to the caller need to be cleaned up somehow.

The assignment operator example was meant to show that you can use any argument or return value.
Doing so beyond a normal assignment can make code hard to read. An assignment operator for a
window class that takes a document object and returns a file pointer isn't going to make much
sense, but you can do it. You can also do anything you want in the implementation - you don't
have to actually assign anything. Again, it would add confusion - we normally expect '=' to
do an assignment.

Mark


Mark Salsbery
Microsoft MVP - Visual C++


This episode brought to you by the number 3

QuestionRandom text Pin
dellthinker14-Jul-07 9:26
dellthinker14-Jul-07 9:26 
AnswerRe: Random text Pin
Perspx14-Jul-07 10:59
Perspx14-Jul-07 10:59 
AnswerRe: Random text Pin
#realJSOP15-Jul-07 2:01
professional#realJSOP15-Jul-07 2:01 
Questionwrong code Pin
tom groezer14-Jul-07 7:05
tom groezer14-Jul-07 7:05 
AnswerRe: wrong code Pin
Paul Conrad14-Jul-07 7:25
professionalPaul Conrad14-Jul-07 7:25 
AnswerRe: wrong code Pin
Mark Salsbery14-Jul-07 7:27
Mark Salsbery14-Jul-07 7:27 
AnswerRe: wrong code Pin
Mark Salsbery14-Jul-07 7:32
Mark Salsbery14-Jul-07 7:32 
GeneralRe: wrong code Pin
Paul Conrad14-Jul-07 7:37
professionalPaul Conrad14-Jul-07 7:37 
AnswerRe: wrong code Pin
#realJSOP15-Jul-07 2:03
professional#realJSOP15-Jul-07 2:03 
QuestionFP Question Pin
Cmania14-Jul-07 7:02
Cmania14-Jul-07 7:02 
AnswerRe: FP Question Pin
Mike Dimmick14-Jul-07 9:22
Mike Dimmick14-Jul-07 9:22 
QuestionNull pointer Pin
tom groezer14-Jul-07 7:02
tom groezer14-Jul-07 7:02 
AnswerRe: Null pointer Pin
Mark Salsbery14-Jul-07 7:37
Mark Salsbery14-Jul-07 7:37 
AnswerRe: Null pointer Pin
c_explorer14-Jul-07 11:54
c_explorer14-Jul-07 11:54 
AnswerRe: Null pointer Pin
#realJSOP15-Jul-07 2:07
professional#realJSOP15-Jul-07 2:07 
QuestionClosing several ui threads together. Pin
neha.agarwal2714-Jul-07 1:50
neha.agarwal2714-Jul-07 1:50 
AnswerRe: Closing several ui threads together. Pin
saravananr_mca15-Jul-07 19:10
saravananr_mca15-Jul-07 19:10 

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.