这是问题的描述。

我定义了以下类。

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();


可视C ++版本:VC ++ 6.0

最佳答案

afx.inl`第122行:
  ASSERT(m_pchData!= NULL); return((CStringData *)m_pchData)-1; }


似乎您的theApp变量未正确初始化,因为其成员aString内部缓冲区是NULL,因此请检查您是否未在初始化之前进行赋值。

此外,还要确保已为Visual Studio 6安装了最新的Service Pack(SP6)。

关于c++ - C++:调试断言失败,afx.inl行122,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38089970/

10-09 13:08