warning C4786!怎么解决?

peterpan 2003-09-03 10:12:06
MSDN上是这样解释的:
The identifier string exceeded the maximum allowable length and was truncated.

我照着他后面的例子做了,没有解决问题。
各位大虾帮帮忙!
...全文
497 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
begginginstorm 2003-09-08
  • 打赏
  • 举报
回复
这个问题在VC6中很常见,没有必要花太多时间应付。其实这个问题只是影响调试(Debug)下面的符号显示和使用符号运算等方面,在Release下是不存在这个问题的。
看一看MSDN的例子:
// SOLUTION1: uncomment the next 4 lines
// #ifdef _DEBUG
// #define VeryLongClassNameA A
// #define VeryLongClassNameB B
// #endif
显然是在定义了_DEBUG才会有这个问题的。而且MSDN中的例子没有错,楼主是不是没有注意到这些注释信息。
firingme 2003-09-05
  • 打赏
  • 举报
回复
一般嵌套模板比较多的时候会出来这个问题,一个接一个的名字空间和嵌套类一下子就超过界限了,特别是元编程的时候,该现象特别突出,不过应该不影响最后的可执行代码……
标识符只是给编译器自己用的东西而已。
peterpan 2003-09-05
  • 打赏
  • 举报
回复
呵呵。
倒不是我的类名太长了。
是template扩展出来以后的类名太长了。
模板实例化以后就超过了255个字符。
例如定义一个std::list<OBJD>::iterator OBJDataMapIter;
其中类OBJD是自己定义的
该死的编译器就这么Warning了。
disable掉当然可以,我就是怕以后再搞一个类OBJH,它认为和类OBJD是一样的就糟了。
偶一向treat warning as error。
还请大家出出注意。

附,MSDN的解决方案
The following example demonstrates that templates with some long class names as their parameters can easily exceed the 255-character limit. Solutions to the problem are also provided.

// C4786.cpp
// compile with: /FR /W3
// C4786 expected
#pragma warning(default : 4786)
// SOLUTION1: uncomment the next 4 lines
// #ifdef _DEBUG
// #define VeryLongClassNameA A
// #define VeryLongClassNameB B
// #endif

// SOLUTION2: An alternative solution:
// uncomment the next 3 lines.
// #ifdef _DEBUG
// #define SomeRandomClass SRC
// #endif
#pragma warning(default : 4786)
template <class A1, class A2, class A3, class A4>
class VeryLongClassNameA{};

template <class B1, class B2, class B3>
class VeryLongClassNameB{};

template <class C1, class C2>
class VeryLongClassNameC{};

template <class D1>
class VeryLongClassNameD{};

class SomeRandomClass{};

typedef VeryLongClassNameD<SomeRandomClass> ClassD ;
typedef VeryLongClassNameC<SomeRandomClass, ClassD> ClassC;
typedef VeryLongClassNameB<SomeRandomClass, ClassC, ClassD> ClassB;
typedef VeryLongClassNameA<SomeRandomClass, ClassB, ClassC, ClassD> ClassA;

void SomeRandomFunction(ClassA aobj){}

int main() {
ClassA AObj;
SomeRandomFunction(AObj);
}

我试过了,不行。
Wanix 2003-09-03
  • 打赏
  • 举报
回复
不必理会
Neptune2003 2003-09-03
  • 打赏
  • 举报
回复
好象是因为使用标准库导致编译的时候系统内部标识符的长度超过255个字节,#pragma warning(disable:4786)就可以了,不用理它.
ezhou 2003-09-03
  • 打赏
  • 举报
回复
是不是你取的名字太长了哦?
CslQy 2003-09-03
  • 打赏
  • 举报
回复
同意楼上。
晨星 2003-09-03
  • 打赏
  • 举报
回复
标志符超长,可能是一些库里的东西名字太长了,可以不必理会。
zhuixe 2003-09-03
  • 打赏
  • 举报
回复
有没有源程序
是不是这样 char cc[10]="sfasdfasdfsdafasdfasdfsdaffsdf";
字符串的长度超过了定义的长度10
fengfeng2003 2003-09-03
  • 打赏
  • 举报
回复
文件前面加上:
#pragma warning(disable:4786)

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧