令人困惑的C ++编译器错误,“无法将'X'转换为'double'作为回报

时间:2011-06-23 16:51:54

标签: c++ compiler-construction compiler-errors

我是相对较新的C ++编程和在Dev C ++中构建一个小程序,它产生以下编译器输出:

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

问题在于我的CNode类的实现,下面显示了'femmedata :: CNode :: GetDistance(double,double)'函数,行号用于显示错误位置。

22 double CNode::GetDistance(double xo, double yo)
23  {
24      return sqrt((x-xo)*(x-xo) + (y-yo)*(y-yo));
25  }

CNode类的定义如下所示:

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:

};

CNode类在NOSEBL.h中声明,实现包含在NOSEBL.cpp中。这些文件还包含其他类定义和实现。但是,CComplex类型在complex.h和complex.cpp中的其他地方定义,并通过包含头文件在此处介绍。

我之前在VC ++ 2010 Express Edition中构建了程序,没有任何问题,所以我不知道这里有什么问题。如果它是相关的,GetDistance函数之后的下几行文本如下所示,它们引用了CComplex类型。

CComplex CNode::CC()
{
    return CComplex(x,y);
}

由于

编辑1

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

1 个答案:

答案 0 :(得分:4)

问题是你得到了错误的sqrt功能。您似乎已包含<complex>标头,但未包含<cmath>标头。 double参数被提升为complex参数,因为此时编译器不知道sqrt的版本double