简体   繁体   English

C ++ Linux编译错误

[英]c++ Linux compilation error

I am getting following error while compiling in linux. 在linux中编译时出现以下错误。

file.cxx:283:9: error: reference to ‘multimap’ is ambiguous
file.cxx:273:47: error: candidates are: std::multimap, std::basic_string > multimap

->piece of sample code is ->示例代码是

static std::multimap<std::string,std::string> multimap;   //line no. 273
//
void foo()
{
    if (multimap.size() == 0)
    {
        multimap.insert( std::pair< std::string, std::string >( "A" , "B" ) );
    }
}

Thanks in advance 提前致谢

You probably have using namespace std; 您可能using namespace std; in the file. 在文件中。 That means your compiler already knows "multimap", which you are trying to define again, in which case the compiler doesn't know which one you mean. 这意味着您的编译器已经知道您要重新定义的“ multimap”,在这种情况下,编译器将不知道您的意思是哪个。

There is a member function in std and you inserted it into your namespace. std中有一个成员function ,您将其插入了名称空间。 Avoid using using namespace std; 避免using namespace std; you can import what you need this way: 您可以通过以下方式导入所需的内容:

using std::multimap;

using std::string;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM