Click here to Skip to main content
15,921,793 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Multiple Window Pin
Mark Salsbery23-Jul-07 20:11
Mark Salsbery23-Jul-07 20:11 
GeneralRe: Multiple Window Pin
Anu_Bala23-Jul-07 20:34
Anu_Bala23-Jul-07 20:34 
GeneralRe: Multiple Window Pin
Mark Salsbery23-Jul-07 20:58
Mark Salsbery23-Jul-07 20:58 
GeneralRe: Multiple Window Pin
Anu_Bala23-Jul-07 21:03
Anu_Bala23-Jul-07 21:03 
QuestionHow to use C++ DLL in VS.NET 2005 Pin
galloping_stallion23-Jul-07 19:40
galloping_stallion23-Jul-07 19:40 
AnswerRe: How to use C++ DLL in VS.NET 2005 Pin
ashukasama25-Jul-07 3:05
ashukasama25-Jul-07 3:05 
QuestionPassing a reference to a pointer Pin
User 58385223-Jul-07 19:21
User 58385223-Jul-07 19:21 
AnswerRe: Passing a reference to a pointer Pin
Arman S.23-Jul-07 20:06
Arman S.23-Jul-07 20:06 
Josh Gray wrote:
One of my colleagues asked me to have a look at some of his code with him. In it he had a method that performed a lookup of an stl collection. If the key was found he retured pointers to two objects through references passed into the method.

bool FindSomethingAndSetThesePointers(const string& key, Class1 *&obj1, Class2 *&obj2);

I sugested that it was pretty unusual way of doing things and looked a little "smelly". When he pressed me on it I found it hard to give a good reason not to do things this way but I still feel a bit uneasy about it. What do you guys think?


I don't think this is 'smelly'. Usually, we do such things when it is really needed. In this case, you should decide what you want to do with the pointers returned. If your collection holds pointers [to some objects], after returned these two pointers, you are able to modify the values of them and thus directly affect the pointers inside the collection. For example,

FindSomethingAndSetThesePointers(""somejey", p, q);

p = NULL;

this will set the corresponding element of the collection to NULL. So you were able to directly change the elements of the collection.

Anyway, if you do not need such freedom of changing the collection outside the FindSomethingAndSetThesePointers, then no need to Class*&, a simple Class* will do.

If your collection holds objects (not pointers to them), you may return either pointer to them, or reference to them, or even a copy of them (if you think it is appropriate).

bool FindSomethingAndSetThesePointers(const string& key, Class1 &obj1, Class2 &obj2);


Sometimes, choosing between Class *' and Class &' is either a matter of taste or a convention.



--
=====
Arman

GeneralRe: Passing a reference to a pointer Pin
Cedric Moonen23-Jul-07 20:22
Cedric Moonen23-Jul-07 20:22 
GeneralRe: Passing a reference to a pointer Pin
codeII23-Jul-07 23:44
codeII23-Jul-07 23:44 
QuestionVC 6.0 TO VC 8.0 POSTMESSAGE() Pin
shakumar_2223-Jul-07 19:11
shakumar_2223-Jul-07 19:11 
QuestionRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
Mark Salsbery23-Jul-07 19:25
Mark Salsbery23-Jul-07 19:25 
AnswerRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
shakumar_2223-Jul-07 19:36
shakumar_2223-Jul-07 19:36 
GeneralRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
Mark Salsbery23-Jul-07 19:41
Mark Salsbery23-Jul-07 19:41 
GeneralRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
shakumar_2223-Jul-07 19:58
shakumar_2223-Jul-07 19:58 
GeneralRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
Mark Salsbery23-Jul-07 20:05
Mark Salsbery23-Jul-07 20:05 
GeneralRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
Rage24-Jul-07 1:41
professionalRage24-Jul-07 1:41 
GeneralRe: VC 6.0 TO VC 8.0 POSTMESSAGE() Pin
Mark Salsbery24-Jul-07 4:43
Mark Salsbery24-Jul-07 4:43 
QuestionProblem in GDI+ LinearGradientBrush Pin
Naveen23-Jul-07 18:36
Naveen23-Jul-07 18:36 
AnswerRe: Problem in GDI+ LinearGradientBrush Pin
Mark Salsbery23-Jul-07 19:11
Mark Salsbery23-Jul-07 19:11 
GeneralRe: Problem in GDI+ LinearGradientBrush Pin
Naveen23-Jul-07 19:14
Naveen23-Jul-07 19:14 
GeneralRe: Problem in GDI+ LinearGradientBrush Pin
Mark Salsbery23-Jul-07 19:20
Mark Salsbery23-Jul-07 19:20 
GeneralRe: Problem in GDI+ LinearGradientBrush Pin
Naveen23-Jul-07 20:12
Naveen23-Jul-07 20:12 
GeneralRe: Problem in GDI+ LinearGradientBrush Pin
Mark Salsbery23-Jul-07 20:29
Mark Salsbery23-Jul-07 20:29 
GeneralRe: Problem in GDI+ LinearGradientBrush Pin
Naveen23-Jul-07 20:38
Naveen23-Jul-07 20:38 

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.