Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inherited Templates – C++

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use this syntax

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading