Reputation: 79595
I want to create a class with a template constructor:
class foo
{
template <class T> foo(T var) {}
};
This compiles in VS2008, but I have no idea if it is a non-standard extension, or if the C++ standard allows it.
Upvotes: 6
Views: 1452
Reputation:
In [temp.mem]:
A template can be declared within a class or class template; such a template is called a member template.
Constructors are members and it isn't explicitly disallowed to make them templates.
For example, std::shared_ptr
has many template constructors.
Upvotes: 6