0

对于以下代码行,我收到以下编译错误,说明模板参数的数量错误。你能告诉我这个声明有什么问题吗?在我看来没问题。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:

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

1 回答 1

6

模板应该只是类型。您为第一个提供了类似声明的语法:

std::map<ServicePartitionKey key, std::vector<EndPointAddr*>* > mServiceMap;
//                           ^^^

它应该只是:

std::map<ServicePartitionKey, std::vector<EndPointAddr*>* > mServiceMap;
于 2013-03-25T18:15:28.853 回答