MLUG: Re: [MLUG] C/C++ programming in Linux
Re: [MLUG] C/C++ programming in Linux
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
First, I'll have you know that I actually moved two boxes in order to
get to the one that has my old books in it so I could get the c++ book
out.

Now, the + operator is a binary operator and when you overload it as
part of a class (as opposed to overloading it with a non-member
function), you only pass it the part after the + as an argument.  The
part before the + is the current object.  Overloading + is like
shorthand for having a method called add().
Instead of saying 
one.add(two)

you can say
one + two

Of course it's been literaly years since I've actually done any of this,
so I'm going from memory and a two second lookup in the book and I could
be completly wrong. (And for sure my syntax sucks)

-Nimrod

On Tue, Apr 02, 2002 at 12:41:39AM -0600, Ryan Linneman wrote:
> Hopefully at least some of you have done c or c++ programming in linux 
> before, anyway this is my first time doing so.  I'm writing a 3d point 
> ADT in c++ and was overloading some of the operators.  When I compile 
> what I have thus far I get errors on all the lines in my header file 
> about the operators.  I'm using the command 'g++ -ggdb3 -Wall -o point3d 
> point3d.cpp' to compile it.  The lines I'm getting the errors on are like
>    point3d operator+(const point3d&, const point3d&) const;
> and the error I'm getting from g++ is
>    `point3d::operator+(const point3d&, const point3d&)' must take 
> either zero or one argument
> when I change the line to be
>    point3d operator+(const point3d&) const;
> everything compiles fine. My questions are, is this something I'm doing 
> wrong, if so then what.?  If everything I have is right, why is the 
> compiler giving me problems?  Any input would be greatly appereciated.
> 
> Ryan Linneman
> 
> -- 
> Debian, because It's GNU Not Unix.
> 
> 
> 
> --
> To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
> 
> Archives are available at http://mlug.missouri.edu/list-archives/
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/