Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGet current position of pointer using IStream interface Pin
MrKBA8-Sep-09 1:16
MrKBA8-Sep-09 1:16 
AnswerRe: Get current position of pointer using IStream interface Pin
Stuart Dootson8-Sep-09 3:43
professionalStuart Dootson8-Sep-09 3:43 
GeneralRe: Get current position of pointer using IStream interface Pin
MrKBA9-Sep-09 0:19
MrKBA9-Sep-09 0:19 
GeneralRe: Get current position of pointer using IStream interface Pin
Stuart Dootson9-Sep-09 3:20
professionalStuart Dootson9-Sep-09 3:20 
QuestionSome C++ Concepts Pin
hrishiS8-Sep-09 1:07
hrishiS8-Sep-09 1:07 
AnswerRe: Some C++ Concepts Pin
«_Superman_»8-Sep-09 1:12
professional«_Superman_»8-Sep-09 1:12 
GeneralRe: Some C++ Concepts Pin
hrishiS8-Sep-09 1:16
hrishiS8-Sep-09 1:16 
GeneralRe: Some C++ Concepts Pin
Cedric Moonen8-Sep-09 1:21
Cedric Moonen8-Sep-09 1:21 
GeneralRe: Some C++ Concepts Pin
hrishiS8-Sep-09 1:27
hrishiS8-Sep-09 1:27 
GeneralRe: Some C++ Concepts Pin
Cedric Moonen8-Sep-09 1:35
Cedric Moonen8-Sep-09 1:35 
GeneralRe: Some C++ Concepts Pin
N a v a n e e t h8-Sep-09 1:28
N a v a n e e t h8-Sep-09 1:28 
GeneralRe: Some C++ Concepts Pin
hrishiS8-Sep-09 1:31
hrishiS8-Sep-09 1:31 
GeneralRe: Some C++ Concepts Pin
Alan Balkany8-Sep-09 5:48
Alan Balkany8-Sep-09 5:48 
GeneralRe: Some C++ Concepts Pin
«_Superman_»8-Sep-09 1:30
professional«_Superman_»8-Sep-09 1:30 
GeneralRe: Some C++ Concepts Pin
hrishiS8-Sep-09 1:33
hrishiS8-Sep-09 1:33 
GeneralRe: Some C++ Concepts Pin
Selvam R8-Sep-09 2:10
professionalSelvam R8-Sep-09 2:10 
GeneralRe: Some C++ Concepts Pin
David Crow8-Sep-09 3:08
David Crow8-Sep-09 3:08 
QuestionFunction out of scope Pin
Nandu_77b8-Sep-09 0:54
Nandu_77b8-Sep-09 0:54 
AnswerRe: Function out of scope Pin
«_Superman_»8-Sep-09 1:05
professional«_Superman_»8-Sep-09 1:05 
AnswerRe: Function out of scope Pin
hrishiS8-Sep-09 1:13
hrishiS8-Sep-09 1:13 
GeneralRe: Function out of scope Pin
Cedric Moonen8-Sep-09 1:46
Cedric Moonen8-Sep-09 1:46 
hrishiS wrote:
the problem I could notice is that, ret is a automatic variable , so it is no longer available once it comes out from the function ToStr().


A copy of the object will be returned, so no there's no problem there.


hrishiS wrote:
Either you can have it as global variable, or make a variable of pointer/reference of String , inside fun and pass it to ToStr


1) global variable for that is really ugly (but that's my personal taste)
2) variable of type pointer: not really nice neither because each time you will create the object on the stack and furthermore, you delegate the destruction of the pointer to somewhere else, which potentially introduce memory leaks.
3) return a reference to the object: that's wrong. In this case, the object will be destroyed, no copy will be made and you will return the address of the destroyed object which is wrong.

So in conclusion, returning the object as he mentioned is the best option.
I could agree with superman in the sense that his proposed solution is more efficient: no temporary object gets created but honestly, it doesn't make a lot of difference (unless your code is in a part of the code which should be highly optimized).

Cédric Moonen
Software developer

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

GeneralRe: Function out of scope Pin
hrishiS8-Sep-09 2:09
hrishiS8-Sep-09 2:09 
AnswerRe: Function out of scope [modified] Pin
Cedric Moonen8-Sep-09 1:17
Cedric Moonen8-Sep-09 1:17 
GeneralRe: Function out of scope Pin
Stuart Dootson8-Sep-09 3:52
professionalStuart Dootson8-Sep-09 3:52 
GeneralRe: Function out of scope Pin
Cedric Moonen8-Sep-09 3:55
Cedric Moonen8-Sep-09 3:55 

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.