Class does not name a type error even when class header file included in C++?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This occurs for my first member function for the class 'complex_test' (the constructor) so I assume I'm getting the same error for the rest of the functions.
FULL ERROR:error: 'complex_test' does not name a type.
The class implementation file below:






#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





The class header for complex_test class:






#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





In addition to this I get an error in the function implementation for the class 'complex' in line 62 for the get_real(), the compiler says it is not in scope, yet I defined it in the very same file?



Exact wording of error: 'get_real' was not declared in this scope.






#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





The header file for class 'complex':






#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif












share|improve this question




















  • 2





    Post the full error messages. Don't paraphrase them.

    – jamesdlin
    Nov 24 '18 at 2:53













  • Your invert, mul, negate, and sub are declared as functions, not member functions.

    – Simon Hobbs
    Nov 24 '18 at 2:56











  • @jamesdlin just added it for both errors

    – Elmer
    Nov 24 '18 at 2:57


















0















This occurs for my first member function for the class 'complex_test' (the constructor) so I assume I'm getting the same error for the rest of the functions.
FULL ERROR:error: 'complex_test' does not name a type.
The class implementation file below:






#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





The class header for complex_test class:






#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





In addition to this I get an error in the function implementation for the class 'complex' in line 62 for the get_real(), the compiler says it is not in scope, yet I defined it in the very same file?



Exact wording of error: 'get_real' was not declared in this scope.






#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





The header file for class 'complex':






#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif












share|improve this question




















  • 2





    Post the full error messages. Don't paraphrase them.

    – jamesdlin
    Nov 24 '18 at 2:53













  • Your invert, mul, negate, and sub are declared as functions, not member functions.

    – Simon Hobbs
    Nov 24 '18 at 2:56











  • @jamesdlin just added it for both errors

    – Elmer
    Nov 24 '18 at 2:57














0












0








0








This occurs for my first member function for the class 'complex_test' (the constructor) so I assume I'm getting the same error for the rest of the functions.
FULL ERROR:error: 'complex_test' does not name a type.
The class implementation file below:






#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





The class header for complex_test class:






#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





In addition to this I get an error in the function implementation for the class 'complex' in line 62 for the get_real(), the compiler says it is not in scope, yet I defined it in the very same file?



Exact wording of error: 'get_real' was not declared in this scope.






#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





The header file for class 'complex':






#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif












share|improve this question
















This occurs for my first member function for the class 'complex_test' (the constructor) so I assume I'm getting the same error for the rest of the functions.
FULL ERROR:error: 'complex_test' does not name a type.
The class implementation file below:






#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





The class header for complex_test class:






#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





In addition to this I get an error in the function implementation for the class 'complex' in line 62 for the get_real(), the compiler says it is not in scope, yet I defined it in the very same file?



Exact wording of error: 'get_real' was not declared in this scope.






#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





The header file for class 'complex':






#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif








#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





#include <fstream>           // For ifstream, ofstream classes
#include "Complex.hpp" // For complex class declaration
#include "ComplexTest.hpp" // For complex_test class declaration

complex_test::complex_test()
{
}

void complex_test::run()
{
std::ifstream fin("complex-in.txt");

std::ofstream fout("complex-out.txt");

int n; fin >> n;

for (int testcase = 0; testcase < n; ++testcase) {
run_test(fin, fout);
}

// Close the input and output files.
fin.close();
fout.close();
}

void complex_test::run_test(ifstream& fin, ofstream& fout)
{
// Read the four double values.
double real1, imag1, real2, imag2;
fin >> real1 >> imag1 >> real2 >> imag2;

complex c1(real1, imag1);

complex c2(real2, imag2);

complex sum = c1.add(c2);
complex diff = c1.sub(c2);
complex product = c1.mul(c2);
complex quotient = c1.div(c2);

fout << "c1 = " << c1.to_string() << ", c2 = " << c2.to_string() << std::endl;
fout << "c1 + c2 = " << sum.to_string() << std::endl;
fout << "c1 - c2 = " << diff.to_string() << std::endl;
fout << "c1 * c2 = " << product.to_string() << std::endl;
fout << "c1 / c2 = " << quotient.to_string() << std::endl;
}





#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





#ifndef COMPLEX_HPP 
#define COMPLEX_HPP

#include <fstream>

using namespace std;

class complex_test {
public:
complex_test();
void run();
private:
void run_test(ifstream& fin, ofstream& fout);
};

#endif





#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





#include <iomanip>      // For fixed, setprecision()
#include <sstream> // For stringstream class
#include "Complex.hpp" // For the complex class declaration
#include <cmath>


complex::complex()
{
init(0,0);
}

complex::complex(double init_real, double init_imag)
{
init(init_real, init_imag);
}

double complex::get_imag()
{
return m_imag;
}

double complex::get_real()
{
return m_real;
}

void complex::init(double init_real, double init_imag)
{
m_real = init_real;
m_imag = init_imag;
}

void complex::set_imag(double s)
{
m_imag = s;
}

void complex::set_real(double s)
{
m_real = s;
}

std::string complex::to_string()
{
std::stringstream sout;
sout << std::fixed << std::setprecision(4);
sout << "(" << get_real();
double imag = get_imag();
if (imag < 0) {
sout << " - " << -imag << 'i';
} else if (imag > 0) {
sout << " + " << imag << 'i';
}
sout << ")";
return sout.str();
}



complex complex::add(complex& rhs_op)
{
double sum_real = get_real() + rhs_op.get_real();
double sum_imag = get_imag() + rhs_op.get_imag();
complex sum(sum_real, sum_imag);
return sum;
}


complex complex::div(complex& rhs_op)
{
complex inverse = rhs_op.invert();
complex quotient = mul(inverse);
return quotient;
}

complex invert()
{
double denom = std::pow(get_real(), 2) + std::pow(get_imag(), 2);
double inv_real = get_real() / denom;
double inv_imag = get_imag() / denom;
complex inverse(inv_real, inv_imag);
return inverse;
}


complex complex::mul(complex& rhs_op)
{
double prob_real = get_real() * rhs_op.get_real() - (get_imag() * rhs_op.get_imag());
double prod_imag = get_imag() * rhs_op.get_real() + (get_real * rhs_op.get_imag());
complex product(prod_real, prod_imag);
return product;
}


complex complex::negate()
{
complex neg(-get_real, -get_imag);
return neg;

}


complex complex::sub(complex& rhs_op)
{
complex negation = rhs_op.negate();
complex diff = add(negation);
return diff;
}





#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif





#ifndef COMPLEX_HPP  
#define COMPLEX_HPP

#include <string>

class complex

{
public:

complex();

complex(double,double);

complex add(complex&);

complex div(complex&);

complex invert();

complex mul(complex&);

complex negate();

complex sub(complex&);

double get_imag();

double get_real();

void set_imag(double);

void set_real(double);

std::string to_string();

private:

void init(double , double );

double m_real;

double m_imag;
};


#endif






c++ class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 3:00







Elmer

















asked Nov 24 '18 at 2:48









ElmerElmer

285




285








  • 2





    Post the full error messages. Don't paraphrase them.

    – jamesdlin
    Nov 24 '18 at 2:53













  • Your invert, mul, negate, and sub are declared as functions, not member functions.

    – Simon Hobbs
    Nov 24 '18 at 2:56











  • @jamesdlin just added it for both errors

    – Elmer
    Nov 24 '18 at 2:57














  • 2





    Post the full error messages. Don't paraphrase them.

    – jamesdlin
    Nov 24 '18 at 2:53













  • Your invert, mul, negate, and sub are declared as functions, not member functions.

    – Simon Hobbs
    Nov 24 '18 at 2:56











  • @jamesdlin just added it for both errors

    – Elmer
    Nov 24 '18 at 2:57








2




2





Post the full error messages. Don't paraphrase them.

– jamesdlin
Nov 24 '18 at 2:53







Post the full error messages. Don't paraphrase them.

– jamesdlin
Nov 24 '18 at 2:53















Your invert, mul, negate, and sub are declared as functions, not member functions.

– Simon Hobbs
Nov 24 '18 at 2:56





Your invert, mul, negate, and sub are declared as functions, not member functions.

– Simon Hobbs
Nov 24 '18 at 2:56













@jamesdlin just added it for both errors

– Elmer
Nov 24 '18 at 2:57





@jamesdlin just added it for both errors

– Elmer
Nov 24 '18 at 2:57












1 Answer
1






active

oldest

votes


















4














The first two lines of both of the shown header files appear to be:



#ifndef COMPLEX_HPP 
#define COMPLEX_HPP


Which means that including either header file will make subsequent inclusion of the other header file a big fat nothing.



P.S. You will also remove more possibilities of other mysterious compilation errors by immediately forgetting that "using namespace std;" is a part of the C++ language. Do yourself a favor and completely get rid of it, especially in header files. It will take a little bit of time getting used it to it, but explicitly referencing the std namespace every time it's needed will quickly become second nature, and mostly an automatic, subconscious process, very quickly.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454762%2fclass-does-not-name-a-type-error-even-when-class-header-file-included-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    The first two lines of both of the shown header files appear to be:



    #ifndef COMPLEX_HPP 
    #define COMPLEX_HPP


    Which means that including either header file will make subsequent inclusion of the other header file a big fat nothing.



    P.S. You will also remove more possibilities of other mysterious compilation errors by immediately forgetting that "using namespace std;" is a part of the C++ language. Do yourself a favor and completely get rid of it, especially in header files. It will take a little bit of time getting used it to it, but explicitly referencing the std namespace every time it's needed will quickly become second nature, and mostly an automatic, subconscious process, very quickly.






    share|improve this answer




























      4














      The first two lines of both of the shown header files appear to be:



      #ifndef COMPLEX_HPP 
      #define COMPLEX_HPP


      Which means that including either header file will make subsequent inclusion of the other header file a big fat nothing.



      P.S. You will also remove more possibilities of other mysterious compilation errors by immediately forgetting that "using namespace std;" is a part of the C++ language. Do yourself a favor and completely get rid of it, especially in header files. It will take a little bit of time getting used it to it, but explicitly referencing the std namespace every time it's needed will quickly become second nature, and mostly an automatic, subconscious process, very quickly.






      share|improve this answer


























        4












        4








        4







        The first two lines of both of the shown header files appear to be:



        #ifndef COMPLEX_HPP 
        #define COMPLEX_HPP


        Which means that including either header file will make subsequent inclusion of the other header file a big fat nothing.



        P.S. You will also remove more possibilities of other mysterious compilation errors by immediately forgetting that "using namespace std;" is a part of the C++ language. Do yourself a favor and completely get rid of it, especially in header files. It will take a little bit of time getting used it to it, but explicitly referencing the std namespace every time it's needed will quickly become second nature, and mostly an automatic, subconscious process, very quickly.






        share|improve this answer













        The first two lines of both of the shown header files appear to be:



        #ifndef COMPLEX_HPP 
        #define COMPLEX_HPP


        Which means that including either header file will make subsequent inclusion of the other header file a big fat nothing.



        P.S. You will also remove more possibilities of other mysterious compilation errors by immediately forgetting that "using namespace std;" is a part of the C++ language. Do yourself a favor and completely get rid of it, especially in header files. It will take a little bit of time getting used it to it, but explicitly referencing the std namespace every time it's needed will quickly become second nature, and mostly an automatic, subconscious process, very quickly.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 2:55









        Sam VarshavchikSam Varshavchik

        64.1k53783




        64.1k53783
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454762%2fclass-does-not-name-a-type-error-even-when-class-header-file-included-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings