尝试在Ubuntu 12.04上的clang-3.3和clang-3.0中使用std :: map时遇到问题:
#include
#include
#include
class A
{
public:
#if 0 //clang compiles ok
typedef std::map<:string> MapKeyValue_t;
void PrintMap(const MapKeyValue_t &my_map
= MapKeyValue_t())
#else // clang compiles fail
void PrintMap(const std::map<:string> &my_map
= std::map<:string>())
#endif
{
std::map<:string>::const_iterator it;
for (it = my_map.begin(); it != my_map.end(); it++)
{
std::cout << it->first << " " << it->second << std::endl;
}
}
};
int main()
{
A a;
a.PrintMap();
return 0;
}
但是,虽然代码在g和clang中编译,但我仍然将这些错误作为输出:
test.cpp:14:36: error: expected ')'
= std::map<:string>())
^
test.cpp:13:15: note: to match this '('
void PrintMap(const std::map<:string> &my_map
^
test.cpp:14:24: error: expected '>'
= std::map<:string>())
^
test.cpp:28:13: error: too few arguments to function call, expected 2, have 0
a.PrintMap();
~~~~~~~~~~ ^
test.cpp:13:2: note: 'PrintMap' declared here
void PrintMap(const std::map<:string> &my_map
^
3 errors generated.
但是,我不知道出了什么问题.希望有人能够对此有所了解.
更新:
void PrintMap(const std::map<:string> &my_map
= (std::map<:string>()))
没关系.谢谢.