Inherited Templates - C++

50 Views Asked by At

I have a template base class and an inherited class. There is a function inside the baseclass which can accept difference types, I expected that I would call this from inside the inherited class with 'BaseClass::Add();' but I instead receive the error "expected primary-expression before ‘>’ token".

How do I call BaseClass::Add with U?

template <typename T>
class BaseClass 
{
public:
    template <typename U>
    void Add() {
        // Do stuff
    }
};

template <typename T>
class InheritedClass : public BaseClass<T>
{
public:
    template <typename U>
    void Add() {
        BaseClass<T>::Add<U>(); // Error here
    }
};

Thanks in advance

1

There are 1 best solutions below

1
On BEST ANSWER

Use this syntax

BaseClass<T>::template Add<U>()