c++ - {ctor} 不是 <BaseClass> 的成员

标签 c++ inheritance constructor

我有一个名为 GLObject 的基类,具有以下 header :

class GLObject{
    public:
        GLObject(float width = 0.0, float height = 0.0, float depth = 0.0, 
                 float xPos= 0.0, float yPos = 0.0, float zPos =0.0, 
                 float xRot =0.0, float yRot = 0.0, float zRot = 0.0);
    ... //Other methods etc
};

还有一个 CPP:

GLObject::GLObject(float width, float height, float depth, 
                    float xPos, float yPos, float zPos, 
                    float xRot, float yRot, float zRot){
    this->xPos = xPos;
    this->yPos = yPos;
    this->zPos = zPos;
    this->xRot = xRot;
    this->yRot = yRot;
    this->zRot = zRot;
    this->width = width;
    this->height = height;
    this->depth = depth;
}

接下来我有一个派生类: header :

class GLOColPiramid : public GLObject
{
public:
    GLOColPiramid(float width, float height, float depth, float xPos = 0.0, float yPos = 0.0, float zPos = 0.0, float xRot = 0.0, float yRot = 0.0, float zRot = 0.0);
    ...
};

cpp文件

GLOColPiramid::GLOColPiramid(float width, float height, float depth, float xPos, float yPos, float zPos, float xRot, float yRot, float zRot) : GLObject::GLObject(width, height, depth, xPos,yPos,zPos,xRot,yRot,zRot)
{

}

这给了我一个错误:

glocolpiramid.cpp:4: error: C2039: '{ctor}' : is not a member of 'GLObject'

为什么?

我正在使用 Qt 4.8.4 和 MSVC2010 32 位编译器

最佳答案

尝试从声明中的 GLObject::GLObject 中删除 GLObject::

在包含GLOColPiramid 实现的.cpp 文件中:

GLOColPiramid::GLOColPiramid( .... ) : GLObject::GLObject( .... )
                                       ^^^^^^^^^^

在C++中是合法的,但测试一下,可能MSVC2010有问题。

关于c++ - {ctor} 不是 <BaseClass> 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16461265/

相关文章:

c++ - 类实例化语法

c++ - 在 C++ 中检查 vector 的所有元素是否相等

C++ : Restrict method access in derived class

c# - 类型不能用作泛型类型或方法中的类型参数 'T' - 为什么?

python - 如何在 Python 单元测试中 stub time.sleep()

java - 使用 super 关键字从不同包调用基类的 protected 构造函数

c++ - 将类构造函数重载放在同一类的另一个重载中

C++11 并行化 : bottleneck in Armadillo's set_seed_random()

c++ - C++ 中带有 std::vector 的 const

inheritance - 覆盖上层类(Class)的变量