gpt4 book ai didi

c++ - ‘>’ 标记之前的预期主表达式

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:24 25 4
gpt4 key购买 nike

<分区>

我有这样的代码:

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;
}

它在 MSVC 下成功编译(并工作),但 gcc 提示语法无效:

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

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

我做错了什么? int protoId = helper.GetProtocolId();

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com