{ctor} is not part of <BaseClass>

I have a base class called GLObject, with the following heading:

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 }; 

And 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; } 

Next I have a derived class: 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 file

 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) { } 

This gives me an error:

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

why?

I am using Qt 4.8.4 with 32-bit MSVC2010 compiler

+4
source share
2 answers

Try removing GLObject:: from GLObject::GLObject in the declaration.

In the .cpp file that contains the GLOColPiramid implementation:

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

This is legal in C ++, but test it, maybe MSVC2010 has problems with it.

+5
source

You should not explicitly reference the base class constructor using the syntax BaseClassName::BaseClassName(...) when calling it from the constructor of the derived class - this is what the compiler complains about.

Instead, just use the name of the base class and pass the parameters:

 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) { } 
+1
source

Source: https://habr.com/ru/post/1479908/


All Articles