使用map在suselinux 使用g++编译出现的编译错误
使用map在g++编译时出现如下问题:
#include <map>
#include <string>
using namespace std;
typedef std::map <const char*, char* > StringMap;
StringMap attrBase;
attrBase[ "MsName "] = "ms04 "; //编译错误: error: expected constructor, destructor, or type conversion before token;
我在dev-c++试编译了一下,却可以编译通过,不知这里是什么原因?谢谢
[解决办法]
在我的suse Linux 和 g++没有问题, 估计你把这句attrBase[ "MsName "] = "ms04 "; 移到main() 或function里面就不会有编译错误了.
iclx012$ cat /proc/version
Linux version 2.6.5-7.151-smp (geeko@buildhost) (gcc version 3.3.3 (SuSE Linux)) #1 SMP Fri Mar 18 11:31:21 UTC 2005
iclx012$ more map.c
#include <map>
#include <string>
#include <iostream>
using namespace std;
typedef std::map <const char*, char* > StringMap;
StringMap attrBase;
int main()
{
attrBase[ "MsName "] = "ms04 ";
cout < <attrBase[ "MsName "] < <endl;
}
iclx012$ g++ map.c
iclx012$ ./a.out
ms04
iclx012$