I am trying to create a program which will have two classes of rational and complex numbers. I made two global functions for their addition and then made those functions friend of both the classes.
While the friend syntax worked fine for the Rational class, it is giving some error in Complex class due to which I am getting an error whenever I try to access the data members of complex class in that function.
Can anyone help in identifying that error, please? Thank you!
Here's the code.
(Just to be clear, I am getting errors at Line 42, 43, 49, and 50)
> Just to be clear, I am getting errors at Line 42, 43, 49, and 50
if you just bothered to paste the errors...
you are getting an error on line 5 and 6
foo.cpp|5 col 40| error: ‘rational’ has not been declared
foo.cpp|6 col 9| error: ‘rational’ does not name a type; did you mean ‘atoll’?
at that point the compiler has no idea what `rational' may be, you need to forward declare it.
1 2 3
class rational; //line 3, note the semicolon
class complex{
//...
Oh, didn't notice that. Thanks for pointing it out ^_^
There were actually too many errors to paste them here :| so I instead decided to only mention those lines where there was underlined syntax indicating an error.
As for addition function, yes, will work on that :P it's just a start... Thank you.