Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
member initial list
//g++ 5.4.0 #include <iostream> using std::cout; class Obj{ public: Obj(){ cout<<"call default ctor\n"; } Obj(const Obj& c){ cout<<"call copy ctor\n"; } Obj(int val){ cout<<"call other ctor\n"; } ~Obj(){ cout<<"destroy obj\n"; } }; class Test : public Obj // inherit from Obj { // 3 member Obj a; Obj b; Obj c; public: Test() // this ctor construct base class by Obj(), and members from a to c by Obj() { cout<<"Test call default ctor\n"; } Test(int val) :Obj(val), // construct base class by Obj() a(), // construct by Obj() b(val), // construct by Obj(int val) c(this->b) // construct by Obj(const Obj& c) { cout<<"Test call other ctor\n"; } }; int main() { Test a; // would call default ctor. cout<<"-----------------------\n"; Test b(); // would call defalt ctor, but not construct any object. cout<<"-----------------------\n"; Test c(10); // would call Test(int). cout<<"-----------------------\n"; Test* d = new Test(); // call Test(). cout<<"-----------------------\n"; Test* e = new Test(10); // call Test(int). cout<<"-----------------------\n"; }
run
|
edit
|
history
|
help
0
VecScalMultiOpLaod
Rzutka gra 2
Test 12(2021)
Destroy It!
Test Swap Functions
Iviewb
2720
Count of factors
InverseMatrix2n2
Vector+Memory_Adv_C++_Tutorial