简体   繁体   中英

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

here is the description of the problem.

I have the following class defined..

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

in another class function, I do this

theApp.aString = "test string";

then I get the runtime error debug assertion failed, afx.inl line 122; please advise.

I tried to do the allocation inside the class as well but it fails flagging the same runtime error.

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

    //in another class function

    theApp.set_string();

visual c++ version: VC++ 6.0

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

It seems, that your theApp variable is not initialized properly, since its members aString internal buffer is NULL , check that you are not making an assignment before its initialization.

Also ensure that you have the latest service pack (SP6) installed for the Visual Studio 6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM