new T and new T()

    技术2022-05-11  118

    class T{public: T() {  cout<<"T()"<<endl; }};

     int* p = new int(); //初始化为0 int* q = new int; //不初始化 cout<<*p<<endl; cout<<*q<<endl;

     T* t = new T;//调用默认构造函数 t = new T();//调用默认构造函数,这两者没有区别


    最新回复(0)