Hello,
when i try to compile this program (it has three parts) I receive an error message that confuses me. Below are the code and error message.
#include <iostream>
using std::cout;
using std::endl;
#include "Complex.h"
int main()
{
Complex x(2, 3), y(4, 5), z;
x.printComplex();
cout << " + ";
y.printComplex();
cout << " = ";
x.add(y);
x.printComplex();
cout << '\n';
x.setComplexNumber(10, 1); //reset Real
y.setComplexNumber(11, 5); //reset Imaginery
x.printComplex();
cout << " - ";
y.printComplex();
cout << " = ";
x.subtract(y);
x.printComplex();
cout << '\n';
x.equal(y);
cout << endl;
return 0;
}
#ifndef Complex_H
#define Complex_H
class Complex {
public:
Complex(double = 0.0, double = 0.0); //default constructor
Complex Complex::add(Complex &);
Complex Complex::subtract(Complex &);
void printComplex(void);
void setComplexNumber(double, double);
Complex Complex::equal(Complex &x);
private:
double realPart;
double imagineryPart;
}
#endif
#include <iostream>
using std::cout;
#include <Complex.h>
Complex::Complex(double real, double imaginery)
{ setComplexNumber(real, imaginery); }
void Complex::add(Complex &)
{
realPart += a.realPart;
imagineryPart =+ a.imagineryPart;
}
void Complex::subtract(Complex &)
{
realPart -= s.realPart;
imagineryPart -= s.realPart;
}
void Complex::printComplex(void)
{ cout << '(' << realPart << ", " << imagineryPart << ')'; }
void setComplexNumber(double rp, dounle ip)
{
realPart = rp;
imagineryPart = ip;
}
bool Complex::equal(Complex &x) {
return ((realPart == x.realPart) &&
(imagineryPart == x.imagineryPart));
}
The error msg says:
C:\IS20\Complex Classes\Complex.cpp(16) : error C2556: 'void __thiscall Complex::add(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::add(class Complex &)'
c:\is20\complex classes\complex.h(10) : see declaration of 'add'
C:\IS20\Complex Classes\Complex.cpp(16) : error C2371: 'add' : redefinition; different basic types
c:\is20\complex classes\complex.h(10) : see declaration of 'add'
C:\IS20\Complex Classes\Complex.cpp(17) : error C2065: 'a' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(17) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(18) : error C2228: left of '.imagineryPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(22) : error C2556: 'void __thiscall Complex::subtract(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::subtract(class Complex &)'
c:\is20\complex classes\complex.h(11) : see declaration of 'subtract'
C:\IS20\Complex Classes\Complex.cpp(22) : error C2371: 'subtract' : redefinition; different basic types
c:\is20\complex classes\complex.h(11) : see declaration of 'subtract'
C:\IS20\Complex Classes\Complex.cpp(23) : error C2065: 's' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(23) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(24) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(30) : error C2061: syntax error : identifier 'dounle'
C:\IS20\Complex Classes\Complex.cpp(33) : error C2065: 'ip' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(36) : error C2556: 'bool __thiscall Complex::equal(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::equal(class Complex &)'
c:\is20\complex classes\complex.h(14) : see declaration of 'equal'
C:\IS20\Complex Classes\Complex.cpp(36) : error C2371: 'equal' : redefinition; different basic types
c:\is20\complex classes\complex.h(14) : see declaration of 'equal'
I do not understand what that means. Can anyone help me? Thanks so much, I really appreciate it a lot.