mercredi 5 avril 2017

inherit from property of templated class within templated class

I'm trying to do the following:

#include <memory>
#include <vector>

template<typename T>
class Base
{
public:
    using SharedPtr = std::shared_ptr<Base<T>>;
};

template<typename T>
class BaseVector : public std::vector<Base<T>::SharedPtr>
{};

int main(int argc, char* argv[])
{
    BaseVector<int> v;
    return 0;
}

But I get the following error:

$ g++ -std=c++11 -o template template.cpp
template.cpp:12:57: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
class BaseVector : public std::vector<Base<T>::SharedPtr>
template.cpp:12:57: note:   expected a type, got ‘Base<T>::SharedPtr’
template.cpp:12:57: error: template argument 2 is invalid

I gather this is because the compiler does not know that Base::SharedPtr is a type. How do I define it in the template arguments of BaseVector such that I can inherit from properties of Base?

Aucun commentaire:

Enregistrer un commentaire