#include
using namespace std;
// g++ Untitled-2.cpp -fno-elide-constructors
class Base {
int data;
public:
Base(int input = 100) : data(input)
{
cout << “Base one construct!” << endl;
}
Base(const Base &in) : data(in.data)
{
cout << “Base copy construct!” << endl;
}
Base(const Base &&in) : data(in.data)
{
cout << “Base move construct!” << endl;
}
virtual void Print()
{
cout << “Base class!” << endl;
}
};
class Derive : public Base {
string name;
public:
Derive(string input = “Derive”) : Base()
{
cout << “Derive one construct!” << endl;
}
Derive(const Derive &in) : Base(in), name(in.name)
{
cout << “Derive copy construct!” << endl;
}
Derive(const Derive &&in) : Base(in), name(in.name)
{
cout << “Derive move construct!” << endl;
}
void Print() override
{
cout << “Print class!” << endl;
}
};
void TFunC(Base in1, Base *in2, Base &in3)
{
cout << “Base in1!” << endl;
in1.Print();
cout << “Base in2!” << endl;
(*in2).Print();
cout << “Base in3!” << endl;
in3.Print();
}
int main()
{
Derive a;
Derive b = a;
Derive *ptr = &a;
TFunC(a, &a, a);
Base c = a; // sliced
// Derive d = c;
cout << sizeof(Base) << endl;
cout << sizeof(Derive) << endl;
system("PAUSE");
return 0;
}