开启左侧

warning C4503 超出修饰名的长度,名称被截断 如何解决?

[复制链接]
Criss 发表于 2018-5-31 15:49:20 | 显示全部楼层 |阅读模式
程序中定义了一些新类型从map和vector,然后就出现了下面的错误:
  1. warning C4503 超出修饰名的长度,名称被截断  
复制代码
查看了官方的文档:https://msdn.microsoft.com/en-us/library/074af4b6.aspx

说白了就是如果你定义了下面这些类型就会出现C4503错误:
  1. // C4503.cpp  
  2. // compile with: /W1 /EHsc /c  
  3. // C4503 expected  
  4. #include <string>  
  5. #include <map>  
  6.   
  7. class Field{};  
  8.   
  9. typedef std::map<std::string, Field> Screen;  
  10. typedef std::map<std::string, Screen> WebApp;  
  11. typedef std::map<std::string, WebApp> WebAppTest;  
  12. typedef std::map<std::string, WebAppTest> Hello;  
  13. Hello MyWAT;  
复制代码

那么要有效解决这个问题怎么办? 我们可以定义一个结构体struct把这些定义写到结构体里面即可,参考下面即可有效解决C4503错误。
  1. // C4503b.cpp  
  2. // compile with: /W1 /EHsc /c  
  3. #include <string>  
  4. #include <map>  
  5.   
  6. class Field{};  
  7. struct Screen2 {  
  8.    std::map<std::string, Field> Element;  
  9. };  
  10.   
  11. struct WebApp2 {  
  12.    std::map<std::string, Screen2> Element;  
  13. };  
  14.   
  15. struct WebAppTest2 {  
  16.    std::map<std::string, WebApp2> Element;  
  17. };  
  18.   
  19. struct Hello2 {  
  20.    std::map<std::string, WebAppTest2> Element;  
  21. };  
  22.   
  23. Hello2 MyWAT2;  
复制代码
这个问题的原因官方文档说是超过了编译器限制的大小4096了,所以通过这种方式将类型换一种方式存在,这样单个类型就标识符就不会超标了。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表