gpt4 book ai didi

c++ - C4503 警告?我该如何解决/摆脱它们?

转载 作者:可可西里 更新时间:2023-11-01 17:19:13 24 4
gpt4 key购买 nike

这是我第一次尝试 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

最佳答案

我不喜欢禁用警告,因为根据我的研究,此警告可能会产生意想不到的后果,所以我更愿意真正解决这个问题。

下面是我将如何重写代码:

typedef struct DA {
string read_mode;
string data_type;
void *pValue;
void *pVarMemLoc;
}DA;
struct ROOM{
map<string, DA*> map;
};
struct DEPARTMENT{
map<string, ROOM> map;
};
struct FLOOR{
map<string, DEPARTMENT> map;
};
struct STAGE{
map<string, FLOOR> map;
};
struct LEVEL{
map<string, STAGE> map;
};

你可以这样使用它:

int main()
{
LEVEL DATA;

DATA.map["lvl1"].map["stg1"].map["flr1"].map["dep1"].map["rom1"] = new DA;
DATA.map["lvl1"].map["stg1"].map["flr1"].map["dep1"].map["rom2"] = new DA;
DATA.map["lvl1"].map["stg1"].map["flr1"].map["dep1"].map["rom3"] = new DA;

...
etc

我的担忧和最终解决方案主要来自MSDN .

关于c++ - C4503 警告?我该如何解决/摆脱它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3994500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com