【发布时间】:2011-04-29 00:19:18
【问题描述】:
这是我第一次尝试 C++ STL。我正在尝试使用 map 构建一个多维关联数组。例如:
typedef struct DA {
string read_mode;
string data_type;
void *pValue;
void *pVarMemLoc;
}DA;
int main()
{
map<string, map<string, map<string, map<string, map<string, DA*>>>>> DATA;
DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom1"] = new DA;
DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom2"] = new DA;
DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom3"] = new DA;
IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom1"]->read_mode = "file";
IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom2"]->read_mode = "poll";
IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom3"]->read_mode = "report";
return 0;
}
在 VS2005 中编译上述代码时,我收到了 170 个 C4503 警告。 所有警告都是关于“超出装饰名称长度,名称被截断”。 该程序似乎运行良好。
有人愿意花点时间向我解释导致这些警告的原因以及我该如何解决这些警告?在此先感谢:)
Warning 1 warning C4503: 'std::map<_Kty,_Ty>::~map' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 2 warning C4503: 'std::map<_Kty,_Ty>::map' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 3 warning C4503: 'std::map<_Kty,_Ty>::operator []' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 4 warning C4503: 'std::_Tree<_Traits>::~_Tree' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 5 warning C4503: 'std::map<_Kty,_Ty>::operator []' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 6 warning C4503: 'std::_Tree<_Traits>::iterator::~iterator' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 7 warning C4503: 'std::_Tree<_Traits>::iterator::iterator' : decorated name length exceeded, name was truncated c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
【问题讨论】:
-
我可以建议您使用
boost::shared_ptr而不是原始指针来存储您的*DA吗?否则,释放所有分配的内存很可能会成为一场噩梦。 -
您好,ereOn,感谢您的建议。我需要更多地研究这个。我的程序实际上是一个由主exe调用的exe。在程序中,首先会分配一大堆(可能是数千个)*DA,然后随着程序运行,一些将被释放并根据来自控制命令的控制命令动态分配主程序。
标签: c++ string stl map name-decoration