Visual Studio not able to show the value of 'this' in release mode (with debug information)

后端 未结 8 594
感情败类
感情败类 2020-12-29 11:15

Original question:

Why is the this pointer 0 in a VS c++ release build?

When breaking in a Visual Studio 2008 SP1 release build with the /Zi

8条回答
  •  [愿得一人]
    2020-12-29 11:45

    It isn't the this pointer that is NULL, but rather the pointer you are using to call a member function:

    class A
    {
    public:
        void f() {}
    };
    
    int main()
    {
        A* a = NULL;
        a->f(); // DO'H!  NULL pointer access ...
    
        // FIX
        A* a = new A;
        a->f(); // Aha!
    }
    

提交回复
热议问题