Reputation: 5
When inheriting from a template in child class constructor is it necessary at a call of the parent constructor to specify template parameter. Code example:
template<typename TYPE>
class Association
{
public:
Association(TYPE* object) : m_object(object) {}
private:
TYPE* m_object;
};
class MyClass
{
};
class AssociationToMyClass : public Association<MyClass>
{
// is the constructor correct
AssociationToMyClass(MyClass* object) : Association<MyClass>(object) {}
// or this one?
AssociationToMyClass(MyClass* object) : Association(object) {}
};
Upvotes: 0
Views: 53
Reputation: 72271
Both are correct. Association<MyClass>
is more explicit, but there's an "injected class name" visible for name lookup where Association
means the same as Association<MyClass>
.
Upvotes: 2