程序中定义了一些新类型从map和vector,然后就出现了下面的错误:
- warning C4503 超出修饰名的长度,名称被截断
复制代码 查看了官方的文档:https://msdn.microsoft.com/en-us/library/074af4b6.aspx
说白了就是如果你定义了下面这些类型就会出现C4503错误:
- // C4503.cpp
- // compile with: /W1 /EHsc /c
- // C4503 expected
- #include <string>
- #include <map>
-
- class Field{};
-
- typedef std::map<std::string, Field> Screen;
- typedef std::map<std::string, Screen> WebApp;
- typedef std::map<std::string, WebApp> WebAppTest;
- typedef std::map<std::string, WebAppTest> Hello;
- Hello MyWAT;
复制代码
那么要有效解决这个问题怎么办? 我们可以定义一个结构体struct把这些定义写到结构体里面即可,参考下面即可有效解决C4503错误。
- // C4503b.cpp
- // compile with: /W1 /EHsc /c
- #include <string>
- #include <map>
-
- class Field{};
- struct Screen2 {
- std::map<std::string, Field> Element;
- };
-
- struct WebApp2 {
- std::map<std::string, Screen2> Element;
- };
-
- struct WebAppTest2 {
- std::map<std::string, WebApp2> Element;
- };
-
- struct Hello2 {
- std::map<std::string, WebAppTest2> Element;
- };
-
- Hello2 MyWAT2;
复制代码 这个问题的原因官方文档说是超过了编译器限制的大小4096了,所以通过这种方式将类型换一种方式存在,这样单个类型就标识符就不会超标了。
|