[TriLUG] OT: C++ Question

Randy Barlow rpbarlow at ncsu.edu
Tue Jan 31 11:23:17 EST 2006


Warren Myers wrote:

>I personally prefer #ifndef .. #endif clauses for making sure they're only
>defined once.
>  
>
One of my friends made this suggestion as well, I need to look into it.  
He said #pragma was a pretty compiler specific flag, and this code will 
need to run in Linux, Unix, and Windows, so this is something I need to 
fix too.  Thanks!

>If I recall correctly, since + is a binary operator, you need to have both
>arguments in the function definition:
>  point3d operator+ (point3d &lhs, &vector3d &rhs);
>The minus sign (-) can be either unary or binary, so you need to make sure
>that if you're trying to do a subtraction you have both arguments in the
>function definition.
>  
>
I think you would do this for global operators, but since these are 
members of a class, the class object is assumed to be one of the 
arguments by default, and so you only need to supply one type.

>If the classes reference each other, they eed to be in the same header file.
>Though I would  ask how you plan to add a vector to a point and get a point
>back... so it might make the most sense to put all of the vector operators
>in the vector class, and the point-only operators in the point class.
>
Thanks to you too Warren!

-- 
Randy Barlow
Research Assistant
Department of Electrical and Computer Engineering
North Carolina State University, Raleigh, NC
rpbarlow at ncsu.edu
http://www.electronsweatshop.com




More information about the TriLUG mailing list