Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ function template argument with templated type struct woes

This code unexplicably doesn't compile:

struct sometype
{
    template <typename T>
    T* get() { return nullptr; }
};

template <typename T>
struct anothertype
{
#if 1
    template <typename T2> struct some_wrapper { typedef T2 type; };
    typedef typename some_wrapper<sometype>::type thetype;
#else
    typedef sometype thetype;
#endif
    typedef thetype* Ptr;

    Ptr m_ptr;
    T* get() { return m_ptr->get<T>(); }
};

If I change the #if argument to 0, it is somehow fixed. Can somebody shed some light in this? Please note that the apparently pointless some_wrapper thing actually does something useful in my real code.

I'm using g++ 4.7.1 with -fstd=gnu++11, the error is as follows (pointing to the line where I declare anothertype<T>::get:

error: expected primary-expression before '>' token
error: expected primary-expression before ')' token
like image 535
fincs Avatar asked Feb 06 '13 21:02

fincs


1 Answers

It's tough to tell with all your typedefs, but I'd wager you need:

m_ptr->template get<T>();
like image 109
Ryan Witmer Avatar answered Sep 19 '22 22:09

Ryan Witmer