Reputation: 1705
Is there a way to refer to the base class of the currently provided template? For example,
template <class UserType>
class User
{
public:
User()
{
user_manager_ = std::make_unique<UserType>();
}
private:
std::unique_ptr<UserType::Base> user_manager_; // <-- I want this ptr to be the type of base of UserType i.e. IUserManager
}
Upvotes: 0
Views: 189
Reputation: 556
Nope, because of multiple inheritances in c++. The only way to do something similar is:
struct A {};
struct UserType : public A {
using Base = A;
};
template<class UserType>
class User {
public:
User() {
user_manager_ = std::make_unique<UserType>();
}
private:
std::unique_ptr<typename UserType::Base> user_manager_; // <-- I want this ptr to be the type of base of UserType i.e. IUserManager
};
Upvotes: 1