对于下面的代码行,我收到以下编译错误,指出错误的模板参数数量。你能告诉我这个宣言有什么问题吗?它看起来不错。 ServicePartitionKey的内容在底部给出。
//Line 107 where template arguments issue happens is this declaration line
std::map<ServicePartitionKey key, std::vector<EndPointAddr*>* > mServiceMap;
汇编讯息:
In file included from ServiceRegistrar.hpp:8:0,
from ServiceRegistrar.cpp:7:
../control_api/ServiceRegistrarAPI.hpp:107:66: error: wrong number of template arguments (1, should be 4)
In file included from /usr/include/c++/4.7/map:61:0,
from ../control_api/ServiceRegistrarAPI.hpp:9,
from ServiceRegistrar.hpp:8,
from ServiceRegistrar.cpp:7:
Class ServicePartitionKey
#include <cstdint>
class ServicePartitionKey
{
public:
ServicePartitionKey() {};
ServicePartitionKey(uint32_t instanceNo, uint64_t version);
~ServicePartitionKey() {};
bool operator < (const ServicePartitionKey &rhs) const;
void setInstanceNo(uint32_t instanceNo) { mInstanceNo = instanceNo; }
uint32_t getInstanceNo() const { return mInstanceNo; }
void setVersion(uint64_t version) { mVersion = version; }
uint64_t getVersion() const { return mVersion; }
private:
uint32_t mInstanceNo;
uint64_t mVersion;
};
答案 0 :(得分:5)
模板应该只是类型。你为第一个提供了类似声明的语法:
std::map<ServicePartitionKey key, std::vector<EndPointAddr*>* > mServiceMap;
// ^^^
应该是:
std::map<ServicePartitionKey, std::vector<EndPointAddr*>* > mServiceMap;