jeudi 26 juillet 2018

Calling a static template function within another template function

I'm trying to call a static template function within another class's template function. I have tried Calling a static template method from a template function with no luck.

Attached is an abridged version of my code.

Foo.hpp

class ParentFoo {
    ... 
}

class ChildFoo : public ParentFoo {
    ...
}

Bar.hpp

#include "Foo.hpp"

class Bar {
    public: 
        ...
        template <typename T> static T* getChildFoo();
}

template <typename T>
T* Bar::getChildFoo() {
    ParentFoo* cFoo = ...
    return reinterpret_cast<T*> (cFoo);
}

Baz.hpp

#include "Bar.hpp"

class Baz {
    public:
        template<typename T> void function();
}

template <typename T>
void Baz::function() {
    Bar::getChildFoo<ChildFoo>();           // err - Syntax error
    Bar::template getChildFoo<ChildFoo>();  // err - getChildFoo is not a class template nor a function template

Aucun commentaire:

Enregistrer un commentaire