{ctor} 不是 的成员<BaseClass>
{ctor} is not a member of <BaseClass>
我有一个名为GLObject的基类,其标题如下:
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;
}
接下来我有一个派生类:标题:
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)
{
}
这给我一个错误:
glocolpiramide .cpp:4: error: C2039: '{ctor}':不是"GLObject"
为什么?
我正在使用Qt 4.8.4与MSVC2010 32位编译器
尝试在声明中将GLObject::
从GLObject::GLObject
中移除
在.cpp
文件中包含GLOColPiramid
的实现:
GLOColPiramid::GLOColPiramid( .... ) : GLObject::GLObject( .... )
^^^^^^^^^^
在c++中是合法的,但是测试一下,也许MSVC2010有问题
在从派生类构造函数调用基类构造函数时,不应该使用BaseClassName::BaseClassName(...)
语法显式引用基类构造函数——这就是编译器所抱怨的。
相反,只需使用基类名称并传递参数:
GLOColPiramid::GLOColPiramid(float width, float height, float depth, float xPos, float yPos, float zPos, float xRot, float yRot, float zRot) : GLObject(width, height, depth, xPos,yPos,zPos,xRot,yRot,zRot)
{
}
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 为什么我的 BaseClass:Method 代码编译(带有单冒号)?
- 如何显式调用运算符<<
- 如何在 BaseClass 指针数组中存储指向子类对象的指针?
- 模板操作员&lt;未打电话
- C / CUDA中的模板方法是3个角括号(&lt;&lt;&lt;)
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- 从Baseclass获取其他功能
- C 建造者Clang STD :: Sill,找不到超载的操作员&lt;
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 左角支架解释为操作员&lt;而不是模板参数