I have a component class that defines a static template method of how a Component
should be created in general:
class Component {
protected:
uint32_t id;
Component(uint32_t id) :
id(id) {
}
template<typename T, uint32_t C>
static T* createComponent() {
// content here not relevant
return new T(someParameter);
}
};
Then there is an implementation, for example a Button
. The constructor of this class should not be used directly, instead there is a static method that calls the Component::createComponent
template function.
class Button: public Component {
protected:
Button(uint32_t id) :
Component(id) {
}
public:
static Button* create();
};
The implementation looks like this, passing the type to instantiate and a constant thats used in creation:
Button* Button::create() {
return createComponent<Button, UI_COMPONENT_BUTTON>();
}
Now the problem is, that the compiler complains with "error: 'Button::Button(uint32_t)' is protected". For my understanding, this constructor call should be OK as Button
extends Component
, but this seems to be a problem here.
How can I solve this?