|
It is currently Thu Feb 09, 2012 12:26 am
|
View unanswered posts | View active topics
| Welcome |
|
Welcome to RHAPSODY4YOU
You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, respond to polls, upload and download content, and access many other special features. Registration is fast, simple, and absolutely free, so please, register to join our community today. |
 |
|
 |
|
| Author |
Message |
|
bitblit
|
Post subject: Ampersand-Asteric parameter passing Posted: Mon Jan 26, 2009 10:33 pm |
Joined: Wed Dec 10, 2008 10:51 pm Posts: 138
|
|
I've noticed many of the sample models posted here override the In, InOut, and Out prototypes to remove the ampersand resulting in prototypes that are more familiar. What is the rationale behind defaulting to the following:
In: const $type&
Out: $type*&
InOut: $type&
"In" makes sense. "InOut" kind of makes sense, though as a coder, I would expect to actually use the * operator knowing that I'm handling a pointer. This does make it a little easier since I don't need to care when I actually write my implementation. But "Out" doesn't make much sense to me. I still have to write my implementation as a pointer. Beyond having to use the * in my implementation, how is "Out" different than "InOut"? Why didn't they just call both "Out" and "InOut" $type*? The reference operator just confuses me, and I assume its because I'm missing something.
|
|
|
|
 |
|
bitblit
|
Post subject: Posted: Tue Jan 27, 2009 5:51 pm |
Joined: Wed Dec 10, 2008 10:51 pm Posts: 138
|
|
Nevermind. We thought long and hard about exactly what assembly code is written when passing pointers, and we figured it out. I'm surprised I never found a reason to do this but it makes sense. You have to use *& or ** when you want to actually change the address contained within the pointer, and send it back to the caller. *& is the same as const **. *& is a better fit in c++ because it insulates the user of the function from having to know that its being passed as a pointer. Though I can also see where *& could cause confusion, particularly when using explicit casting..
|
|
|
|
 |
|
Mickey
|
Post subject: Posted: Wed Jan 28, 2009 1:09 pm |
Joined: Thu Aug 30, 2007 4:31 pm Posts: 152 Location: Germany
|
|
you always have the flexibility to change the default settings of IN OUT and INOUT with the properties for example to change IN... CPP_CG->Class->IN
|
|
|
|
 |
|
Farquad
|
Post subject: Posted: Wed Jan 28, 2009 7:01 pm |
Joined: Thu Sep 13, 2007 7:34 pm Posts: 397 Location: London
|
|
Good question well answered by yourself. A lot of people change the defaults but that's often a sign of sub-optimal design.
|
|
|
|
 |
|
bitblit
|
Post subject: Posted: Fri Jan 30, 2009 7:50 pm |
Joined: Wed Dec 10, 2008 10:51 pm Posts: 138
|
|
My first reaction was to override this in the features too. Most of the sample code I find here has this overridden. I'm not always very optimistic, but I figured there must be a reason why it was defaulted to this. After studying it, I've concluded that this is a better way to do it, so I'm leaving it at default.
|
|
|
|
 |
|
|
 |
|
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|