【单选】假定T是一个C++类,下列语句执行之后,内存里创建了()个T对象。
T b(5);
T c[6];
T &d = b;
T e=b;
T *p = new T (4);
#include <iostream> using namespace std; class T { public: T(int m){ cout << "调用构造函数:" << ++num << endl;} //自定义构造函数 T() { cout << "调用默认构造函数:" << ++num << endl; } //默认构造函数 T(T & a){ cout << "调用拷贝构造函数:" << ++num << endl;}//拷贝构造函数 ~T(){cout << "调用析构函数"<<--num << endl;} private: static int num; }; int T::num = 0; int main() { T b(5); T c[6]; T& d = b; T e = b; T* p = new T(4); return 0; }
#include <iostream> using namespace std; class A { private: int n; public: A() { cout << "A()" << endl; } A(int m) :n(m) { cout << "A(int m)" << endl; } A(const A& copy) { cout << "A(const A©)" << endl; } ~A() {} }; int main() { A a(1); //栈中分配 A b = A(1); //栈中分配 A* c = new A(1); //堆中分配 delete c; A d = a; A e(d); A f; return 0; }
#include <iostream> using namespace std; class A { private: int n; public: A() { cout << "A()" << endl; } A(int m) :n(m) { cout << "A(int m)" << endl; } /* A(const A& copy) { cout << "A(const A©)" << endl; } */ ~A() {} }; int main() { A a(1); //栈中分配 A b = A(1); //栈中分配 A* c = new A(1); //堆中分配 delete c; A d = a; A e(d); A f; return 0; }