C++ pointer to class

后端 未结 6 1645
小鲜肉
小鲜肉 2021-01-30 23:11

Can anyone tell me what the difference is between:

Display *disp = new Display();

and

Display *disp;
disp = new Display();
         


        
6条回答
  •  没有蜡笔的小新
    2021-01-31 00:08

    One creates an object of type Display and one of the type GzDisplay, is this on purpose or is it a typo?

    If it's a typo then there's no difference in regards to the code generated but the first method is preferred since there is no time in which the variable disp is in scope and uninitialized.

提交回复
热议问题