1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <iostream> using namespace std;
class Test{ public: Test(int a = 5, int b = 5): ma(a), mb(b){ cout << "Test(int, int)" << endl; } Test(const Test &src): ma(src.ma), mb(src.mb){ cout << "Test(const Test&)" << endl; } void operator=(const Test &src){ ma = src.ma; mb = src.mb; cout << "operator=" << endl; } ~Test() { cout << "~Test()" << endl; } private: int ma; int mb; };
Test t1(10, 10); int main(){ Test t2(20, 20); Test t3 = t2; static Test t4 = Test(30, 30); t2 = Test(40, 40); t2 = (Test)(50, 50); t2 = 60; Test *p1 = new Test(70, 70); Test *p2 = new Test[2]; Test *p3 = &Test(80, 80); const Test &p4 = Test(90, 90); delete p1; delete []p2; } Test t5(100, 100);
|