I have a base class with a protected constructor because this class should not be directly instantiated.
class Transform {
protected:
Transform();
~Transform() {}
public:
glm::vec3 some_member; // value will be initialized in the constructor
... // many other members
}
Then I have many derived classes
class Camera : public Transform {
public:
Camera();
...
}
class Light: public Transform {
public:
Light();
...
}
I'm surprised that the base class constructor is not called by default in the derived constructor, I thought it'd be called automatically, which turned out to be wrong. So now I want to call the base class constructor explicitly so the base class members will be correctly initialized, so I tried:
Camera::Camera() {
Transform::Transform(); // error C2248: cannot access protected member
__super::Transform(); // error C2248: cannot access protected member
}
The base constructor is protected, not private, why can't I access it in derived classes?
Magically, I found that this works fine, but I don't understand why, what's the difference here?
Camera::Camera() : Transform() { // compile successfully
...
}
Transform::Transform();" That would create a temporary object, same asTransform();, if there was noprotected.