c++ - 错误 C2061 : syntax error : identifier 'map'

标签 c++ dictionary visual-studio-2013

我快疯了。我只有一个 header 和 cpp,但无法编译:

.h 如下:

#pragma once

#include <string>
#include <map>
#include <windows.h>



class Activate
{
public:
    Activate();
    ~Activate();

    int accion(map<string, string>& mapa);
};

和 cpp 这一个:

#include "Activate.h"
using namespace std;

Activate::Activate()
{
}


Activate::~Activate()
{
}

int Activate::accion(map<string, string>& mapa){}

我得到了上面提到的错误:

1>c:\users\dani.roca\desktop\autocad files\mfc dll\project1\project1\activate.h(19): error C2061: syntax error : identifier 'map'
1>c:\users\dani.roca\desktop\autocad files\mfc dll\project1\project1\activate.cpp(13): error C2511: 'int Activate::accion(std::map<_Kty,_Ty> &)' : overloaded member function not found in 'Activate'


#include "Activate.h"
using namespace std;

Activate::Activate()
{
}


Activate::~Activate()
{
}

int Activate::accion(std::map<string, string>& mapa){}

还有这个

class Activate
{
public:
    Activate();
    ~Activate();

    int accion(std::map<std::string, std::string>& mapa);
};

然后出现了新的错误:

1>LINK: fatal error LNK1561:必须定义入口点

最佳答案

替换int accion(map<string, string>& mapa);

int accion(std::map<std::string, std::string>& mapa);
//         ^^^^^    ^^^^^        ^^^^^

当您包含 header 时,using namespace std尚未生效。

作为替代方案,您可以添加 using std::map;using std::string;在你的类里面。

class Activate
{
public:
    Activate();
    ~Activate();

    using std::map;
    using std::string;
    int accion(map<string, string>& mapa);
};

关于c++ - 错误 C2061 : syntax error : identifier 'map' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36036070/

相关文章:

c# - Visual Studio 2013 中的自定义 "One ASP.NET"项目模板

C++ "using tcp=x"到 "namespace tcp=x"有什么区别

c# - 将 IEnumerable<string> 转换为字典

dictionary - 当键不在 map 中时不引发错误(如 Python)有什么好处?

visual-studio-2013 - 无法安装 Visual Studio 2013 更新 5 (RTM); Apache Cordova 工具

c++ - 如何更改左上角 : taskbar, 的图标,按下 Alt-Tab 时的图标,我的 .exe

c++ - 将字符转换为整数?

c++ - 驾驶执照考试程序。 cannot convert std::string to std::string 等错误

c++ - cout <<与char *参数一起输出字符串,而不是指针值

python - 使用字典使用 Python 将罗马数字转换为整数