我正在编写描述复杂变量和实变量的代码。
我包含了头文件,似乎在.hpp文件和.cpp文件之间产生冲突。
它们很相似,我无法确定重新定义的位置。
solver.hpp
#include <iostream>
#include <complex>
class RealVariable
{
public:
std::complex<double>c;
RealVariable(double d);
RealVariable();
};
class ComplexVariable
{
public:
std::complex <double>d;
ComplexVariable(double d1,double d2);
ComplexVariable();
};
solver.cpp
#include "solver.hpp"
#include <iostream>
#include <complex>
class RealVariable
{
public:
std::complex<double>c;
RealVariable(double d)
{
c.imag(0);
c.real(d);
}
RealVariable(){}
};
class ComplexVariable
{
public:
std::complex <double>d;
ComplexVariable(double d1,double d2)
{
d.imag(d2);
d.real(d1);
}
ComplexVariable(){}
};
在表面上,定义.hpp和.cpp文件中的文件看起来相同(至少对我而言)。
在您的CPP文件中,仅应执行。
#include "solver.hpp"
RealVariable::RealVariable(double d)
{
c.imag(0);
c.real(d);
}
RealVariable::RealVariable()
{
}
ComplexVariable::ComplexVariable(double d1,double d2)
{
d.imag(d2);
d.real(d1);
}
ComplexVariable::ComplexVariable()
{
}