以下代码测试使用 std::map 和 std::string 作为键:
#include <stdio.h>
#include <map>
#include <string>
using namespace std;
typedef map<string, int> test_map_t;
int main(int argc, char **argv) {
test_map_t test_map;
test_map["test1"]= 1;
test_map["test2"]= 2;
test_map["test3"]= 3;
string tmp= "test1";
printf("%s : %d \n", tmp.c_str(), test_map[tmp]);
return 0;
}
当使用普通 gcc 编译时,该测试将按预期打印出“test1 : 1”。但是,当使用 alchemy 编译时,它会打印“test1 : 3”(!)。这里有些不对劲。
是否有任何解决方法或者我只是卡住了?