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;
}

this looks very familiar to me .... is this for a class? if so, which class? ...

this looks very familiar to me ....

Were you here?

Were you here?

no ... in one of my classes about a year or so ago, i remember doing something VERY close to this, if not the same ..... :-|

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.