6.5.8 Hàm khởi tạo mặc định – default constructors (2)
Hãy xem ví dụ sau →
Trông có vẻ ổn đúng không ? Nhưng sự thật thì không hẳn vậy, chương trình này sẽ có […]
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; class WithConstructor { public: int i; float f; WithConstructor(int a, float b) : i(a), f(b) { } void Display(void) { cout << "i=" << i << ",f=" << f << endl; } }; int main(void) { WithConstructor o1; WithConstructor *o2; o2 = new WithConstructor; o1.Display(); o2 -> Display(); return 0; } |