I want my abstract base class to have a templated constructor, but can't get it to work without an extra parameter to deduct the type from.
I want to do something like this:
class Base {
public:
template <typename T>
Base() {
/*Do something*/
}
virtual void foo() = 0;
};
class Derived : public Base {
public:
Derived() : Base</*Some type*/>() {} // <-- Forbidden
void foo () {}
};
I know that this does not work for non abstract classes because the syntax for constructing them would have the constructor template and a possible class template specification collide* with each other, but I can't see why it wouldn't work for abstract classes since you aren't able to instantiate them on their own.
*(For example with Base<int>() (assuming base is not abstract), it is not clear what the specified template is for. Class template or constructors function template.)
Any help would be greatly appreciated! :)
template <typename T> Base()is not a useable constructor. You cannot call a constructor so there is no way to provide whatTis.std::type_identity<T>is even better.