I can't communicate with Classes in C++. I suck. Fixed.

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Shouldn't Add() take a second complex object (or pointer, or ref) as a parameter?

with ints

class zint
{
public:

int myi ;

void Zadd ( zint z2 ) ;

} ;

void zint :: Zadd ( zint z2 )
{

myi += z2.myi
}


In main()

zint zfoo ( 1) ;
zint zbar ( 5 ) ;

zfoo.Add( zbar ) ;


Your textbook probably has examples like this, or with point ( x, y ) objects for graphics.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Yep, the prototype for add should something like this:

Complex::add(const Complex &x)

It'd be more intuitive to overload the + and += operators though, but you probably haven't gotten there yet.
 

VIAN

Diamond Member
Aug 22, 2003
6,575
1
0
DaveSimmons, you code helped me.

Thanks. After I understood your code and fixed and compiled it, I tried the same thing with my code and it worked.

Thanx.

I'll post the working program, when I make my final changes.

It'd be more intuitive to overload the + and += operators though, but you probably haven't gotten there yet.
I've seen it done and have code on it, but since my class hasn't gotten there, I don't fully understand it, so I'm reluctant to use it. But it doesn't look too difficult.