Вопрос

I have DefineEvent class template that I use to ease the definition of new event classes. It's looks like this (pretty hairy, I know):

template<class EventClass, class... Parents>
class DefineEvent : public virtual Event, public Parents...
{
   public:
     DefineEvent()
     {
         static const EventTypeInfo& info = TypeInfoParentSetter<EventClass>
             ::SetOnce<Parents...>(TypeInfoHolder<EventClass>::Instance());
     }
};

The TypeInfoParentSetter class I used there looks like this:

template<class EventClass>
class TypeInfoParentSetter
{
  public:
    template<class... Parents>
    static const EventTypeInfo& SetOnce(TypeInfoHolder<EventClass>& holder)
    {
        // ...
    }
};

I get a compilation error pointing to the ::SetOnce<Parents...> line in DefineEvent(), telling me that the compiler "expected primary-expression before '...' token". How do I fix this?

You can view the code in context here, but take note that it's pretty ugly.

Это было полезно?

Решение

You need to include one template keyword to denote nested name is template :

DefineEvent()
     {
         static const EventTypeInfo& info = TypeInfoParentSetter<EventClass>
             :: template SetOnce<Parents...>(TypeInfoHolder<EventClass>::Instance());
     }

and you forgot to make member function TypeInfoParentSetter<EventClass>::Set static :

 template<class... Parents>
    static TypeInfoParentSetter<EventClass> Set(TypeInfoHolder<EventClass>& holder)
    {
        std::cout << "ParentSetter()\n";
        return TypeInfoParentSetter<EventClass>();
    }

check it: http://ideone.com/sNHMX

Другие советы

May be you must use "template" keyword before SetOnce:

template<class EventClass, class... Parents>
class DefineEvent : public virtual EventClass, public Parents...
{
   public:
     DefineEvent()
     {
         static const EventTypeInfo& info =
            TypeInfoParentSetter<EventClass>::template SetOnce<Parents ...>(TypeInfoHolder<EventClass>::Instance());
     }
};
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top