I am relatively new to C++ programming and building a small program in Dev C++ which is producing the following compiler output:
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\s0237326\My Documents\Postgrad_Research_Sync_Folder\C_Projects\mfemm2\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\s0237326\My Documents\Postgrad_Research_Sync_Folder\C_Projects\mfemm2\Makefile.win" all
g++.exe -c NOSEBL.CPP -o NOSEBL.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
NOSEBL.CPP: In member function `double femmedata::CNode::GetDistance(double, double)':
NOSEBL.CPP:24: error: cannot convert `CComplex' to `double' in return
NOSEBL.CPP: In member function `double femmedata::CBlockLabel::GetDistance(double, double)':
NOSEBL.CPP:108: error: cannot convert `CComplex' to `double' in return
make.exe: *** [NOSEBL.o] Error 1
Execution terminated
The problem is with the implementation of my CNode class, with the 'femmedata::CNode::GetDistance(double, double)' function shown below, with line number to show the error location.
22 double CNode::GetDistance(double xo, double yo)
23 {
24 return sqrt((x-xo)*(x-xo) + (y-yo)*(y-yo));
25 }
The definition of the CNode class is shown below:
class CNode
{
public:
CNode();
double x,y;
int xs,ys;
bool IsSelected;
CStdString BoundaryMarker;
int InGroup;
double GetDistance(double xo, double yo);
CComplex CC();
void ToggleSelect();
private:
};
The CNode class is declared in NOSEBL.h, and the implementation contained in NOSEBL.cpp. These files also contain other class definitions and implementations. However, the CComplex type is defined elsewhere in complex.h and complex.cpp, and introduced here through including the header file.
I built the program previously in VC++ 2010 Express Edition with no problems, so I don't know what the problem is here. In case it is relevant, the next few lines of text after the GetDistance function are shown below, which do reference the CComplex type.
CComplex CNode::CC()
{
return CComplex(x,y);
}
Thanks
NOSEBL.CPP: In member function `double femmedata::CNode::GetDistance(double, double)':
NOSEBL.CPP:24: error: `class CComplex' used where a floating point value was expected
NOSEBL.CPP:24: error: aggregate value used where a float was expected
NOSEBL.CPP: In member function `double femmedata::CBlockLabel::GetDistance(double, double)':
NOSEBL.CPP:108: error: cannot convert `CComplex' to `double' in return
make.exe: *** [NOSEBL.o] Error 1
The problem is that you are getting the wrong sqrt
function. You appear to have included the <complex>
header but not the <cmath>
header. The double
parameter is being promoted to a complex
parameter because the version of sqrt
that takes a double
is not known to the compiler at that point.