C :调试断言失败,AFX.Inl第122行

C++: Debug assertion failed, afx.inl line 122

本文关键字:AFX Inl 122行 失败 调试 断言      更新时间:2023-10-16

这是问题的描述。

我有以下类定义..

class classA {
public:
  CString aString;
};
extern classA theApp;

在另一个类功能中,我这样做

theApp.aString = "test string";

然后,我得到运行时错误调试断言失败,AFX.inl第122行;请建议。

我也尝试在同类课程内进行分配,但失败了标记相同的运行时错误。

 class classA {
    public:
      CString aString;
      void set_string()
      {
          aString = "test string 2";
      }
    };
    extern classA theApp;
    //in another class function
    theApp.set_string();

Visual C 版本:VC 6.0

afx.inl`线122: 断言(m_pchdata!= null);返回((cstringdata*)m_pchdata)-1;}

看来,您的theApp变量未正确初始化,因为其成员aString内部缓冲区为NULL,请检查您在初始化之前是否没有进行分配。

还确保您为Visual Studio安装了最新的服务包(SP6)6。