C++ Access violation reading location 0xcdcdcdcd error on calling a function

前端 未结 5 1025
醉梦人生
醉梦人生 2020-12-06 21:26

Please consider the below scenario:

I have a header file and its corresponding source file:

exmp.h (Header file)

exmp.cpp (

5条回答
  •  鱼传尺愫
    2020-12-06 22:26

    in order to solve it (one possible way), you must make 'ptr' actually to point to a adress where a myClass objects exists. In order to exist, you have to create it, e.g.

    class sampleClass
    {
    public:
       sampleClass()
       {
           ptr = new myClass();
       }
    private:
       myClass* ptr;
    };
    

    you might still consider using C++11's unique_ptr or shared_ptr instead of a raw pointer, though.

提交回复
热议问题