|
-
April 29th, 2009, 06:07 PM
#4
Re: Operator Overloading, in General
 Originally Posted by Salbrismind
I know a bit, but I don't understand all of what you say:
1) How do I define operator+ and operator- as const member functions. What does that mean?
2) How would I go about do what you said in the second sentence?
3) Const reference? You mean like a pointer to the struct?
Sorry if I'm asking a bit much. Still learning myself.
-Thanks
1:
It means it is a read only function and doesn't modify the object its called on. (http://msdn.microsoft.com/en-us/library/6ke686zh.aspx). This sort of enforcing of rules on your program may not make sense at first, but you'll be happy you did it when you code base gets large and you start forgetting the original intent of a function, or accidently put in some functionality that is unintendedly trying to modify the object you are calling it on. If other people use your code, they'll thank you for it to.
2:
Not sure I'm not that proficient on operator overloading.
3:
Are you a C programmer? You should probably know about references (&) in c++. They are like a pointer in the sense that they are a memory address, except they always point to the same object. passing by reference gives a performance gain because it doesn't copy the object, but simply passes its address in memory so you can access the orginial object. const tells you that the parameters will not be modified in the function. This gives the security of pass by value but the speed of pass by reference.
Last edited by AlastrionaAdair; April 29th, 2009 at 06:22 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|