Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected primary-expression before ‘>’ token [duplicate]

I have a code like:

class Client2ServerProtocol {

};

class ProtocolHelper {
public:
    template<class ProtocolClass>
    int GetProtocolId() {
        return -1;
    }
};

template<> inline int
ProtocolHelper::GetProtocolId<Client2ServerProtocol>() {
    return 1;
}

template<typename PROTOCOL_HELPER>
class Dispatcher {
public:
    template<typename PROTOCOL_CLASS>
    void Subscribe(int msgId) {
        int protoId = helper.GetProtocolId<PROTOCOL_CLASS>();
        printf("Subscribe protoId %d, msgId %d", protoId, msgId);
    }
    PROTOCOL_HELPER helper;
};

int main() {
    Dispatcher<ProtocolHelper> dispatcher;
    dispatcher.Subscribe<Client2ServerProtocol>(1);
    return 0;
}

It compiles successfully (and works) under MSVC, but gcc is complaining about invalid syntax:

test.cc:23:56: error: expected primary-expression before ‘>’ token int protoId = helper.GetProtocolId();

test.cc:23:58: error: expected primary-expression before ‘)’ token

What i'm doing wrong? int protoId = helper.GetProtocolId();

like image 300
ejkoy Avatar asked Jun 23 '16 15:06

ejkoy


1 Answers

You just need to put the template keyword to signify that it follows up a template:

int protoId = helper.template GetProtocolId<PROTOCOL_CLASS>();
                     ^^^^^^^^
like image 80
101010 Avatar answered Sep 24 '22 22:09

101010