C++ pointer to objects

前端 未结 7 586
野趣味
野趣味 2020-12-07 16:19

In C++ do you always have initialize a pointer to an object with the new keyword?

Or can you just have this too:

MyClass *myclass;

mycl         


        
7条回答
  •  情话喂你
    2020-12-07 16:29

    if you want to access a method :

    1) while using an object of a class:

    Myclass myclass;
    myclass.DoSomething();
    

    2) while using a pointer to an object of a class:

    Myclass *myclass=&abc;
    myclass->DoSomething();
    

提交回复
热议问题