Hello dear people of the underworld called the internet.
Lets say we have a class called X with the template parameters(Y):
template
c
X is not a type without its template argument so no, unfortunately not. You could achieve what you want if X had a base class which defined the interface you wanted to use though.
For example,
struct Interface
{
Interface() {}
virtual ~Interface(){}
virtual void doSomething() = 0;
};
template <class Y>
class X : public Interface
{
//...
virtual void doSomething() override;
};
std::unique_ptr<Interface> myClass;
//....
myClass.reset(new X<variable>());
myClass->doSomething();
No. A pointer points to a type, and X
is not a type.
Not with X*
. Consider this alternative:
class BaseX {
//...
};
template<class Y>
class X : public BaseX
{
//...
};
Since BaseX
is a complete type, you can have BaseX*
that references some X<Y>
once you've defined it.