What will happen when I call a member function on a NULL object pointer?

后端 未结 6 1560
闹比i
闹比i 2020-11-22 01:56

I was given the following as an interview question:

class A
{
public:
    void fun()
    {
        std::cout << "fun" << std::endl;
             


        
6条回答
  •  离开以前
    2020-11-22 02:52

    We can't know what will. Everything can happen, because the program exposes undefined behavior. See Does invoking a member function on a null instance cause undefined behavior?.

提交回复
热议问题