Why am I able to make a function call using an invalid class pointer

后端 未结 6 616
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 01:56

In below code snippet, although pointer is not initialized the call is still made successfully

temp *ptr;
ptr->func2();

Is it due to C++

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 02:36

    Its not working. Its just by luck that your application is not crashing where your expecting it to crash. Its not a feature but a side-effect of the compiler which is allowing the function call to seem to work.

提交回复
热议问题