Hello there, why do I have this message when I try to use subTwoComplex in my testing file? The addTwoComplex works fine but not the "sub"one. What's wrong? thanks
error C2039: 'subTwoComplex' : is not a member of 'Complex'
*********header file
#ifndef COMPLEX_H
#define COMPLEX_H
class Complex {
public:
Complex( double = 4.5, double = 5.5 );
Complex addTwoComplex( Complex );
Complex subTwoComplex( Complex );
void print();
void setTwoParts( double, double);
void setReal(double);
void setImaginary(double);
private:
double realPart;
double imaginaryPart;
};
#endif
#include <iostream>
using namespace std;
//using std::cout;
#include "complex.h"
Complex::Complex(double real, double imaginary)
{
realPart = real;
imaginaryPart = imaginary;
}
void Complex::setReal(double r)
{
realPart = r;
}
void Complex::setImaginary(double i)
{
imaginaryPart = i;
}
void Complex::setTwoParts(double really, double imag)
{
setReal(really);
setImaginary(imag);
}
Complex Complex::addTwoComplex( Complex a )
{
Complex addition;
addition.realPart = a.realPart + realPart;
addition.imaginaryPart = a.imaginaryPart + imaginaryPart;
return addition;
}
Complex Complex::subTwoComplex( Complex c )
{
Complex subtraction;
subtraction.realPart = c.realPart - realPart;
subtraction.imaginaryPart = c.imaginaryPart - imaginaryPart;
return subtraction;
}
void Complex::print()
{
cout << "(" << realPart << ", " << imaginaryPart << ")";
}
************testing file
#include <iostream>
using namespace std;
#include "complex.h"
int main()
{
Complex cmplx1;
cout << "Default constructor is : \n" ;
cmplx1.print();
Complex cmplx2 ( 4.4, 5.5 );
Complex cmplx3 ( 2.2, 3.3 );
cout << '\n';
Complex cmplx4 = cmplx2.addTwoComplex(cmplx3);
cmplx4.print();
cout << '\n';
Complex cmplx5 = cmplx3.subTwoComplex(cmplx2);
cmplx5.print();
return 0;
}