我的 C++ 生锈了。我有一个成员变量是unordered_map<some_enum_type, string>
.
我正在尝试在类构造函数中填充地图。我在这里做错了什么?
从我的标题:
#include <iostream>
#include <unordered_map>
using namespace std;
typedef enum{
GET,
POST,
PUT,
DELETE
}http_verb;
class CouchServer{
string host;
int port;
string dbname;
unordered_map<http_verb,string> req_types;
public:
我的构造函数实现:
CouchServer::CouchServer(string host, int port, string dbname){
this->host = host;
this->port = port;
this->dbname = dbname;
this->req_types = {
{req_types[GET], "GET"},
{req_types[POST], "POST"},
{req_types[PUT], "PUT"},
{req_types[DELETE],"DELETE" }
};
}
更新:
阅读提供的答案和评论后,我将标题更改为:
class CouchServer{
string host;
int port;
string dbname;
unordered_map<http_verb,string> req_types;
public:
CouchServer(std::string host, int port, std::string dbname)
: host(std::move(host))
, port(port)
, dbname(std::move(dbname))
, req_types{
{ http_verb::GET, "GET" },
{ http_verb::POST, "POST" },
{ http_verb::PUT, "PUT" },
{ http_verb::DELETE, "DELETE" }
}
{ }
同样的问题仍然存在。我应该提到我正在尝试使用 XCode 4 编译这段代码,也就是说Apple LLVM compiler 4.2。