M
mescaline
//Consider the simple program with inheritance, plain init for A, copy ctr for B
#include <iostream>
using namespace std;
class Base{
public:
Base(){cout << "Base, default" << endl;}
Base(const Base &){cout << "Base, Copy Ctor" << endl;}
};
class Derivedublic Base{
public:
Derived(){cout << "Derived, default" << endl;}
Derived(const Derived &){cout << "Derived, Copy Ctor" << endl;}
}
int main(){
Derived A;
cout << endl;
Derived B(A);
return 0;
}
OUTPUT:
Base, default } for A, Base part
Derived, default } for A, Derived part
Base, default ->Why default when its the base class init for copy-constructed B?
Derived, Copy Ctor } for B, Derived part
What's my mistake so that I'm getting "Base, default" instead of
"Base, Copy Ctor" in the 3 rd line of the Output?
thanks
m
#include <iostream>
using namespace std;
class Base{
public:
Base(){cout << "Base, default" << endl;}
Base(const Base &){cout << "Base, Copy Ctor" << endl;}
};
class Derivedublic Base{
public:
Derived(){cout << "Derived, default" << endl;}
Derived(const Derived &){cout << "Derived, Copy Ctor" << endl;}
}
int main(){
Derived A;
cout << endl;
Derived B(A);
return 0;
}
OUTPUT:
Base, default } for A, Base part
Derived, default } for A, Derived part
Base, default ->Why default when its the base class init for copy-constructed B?
Derived, Copy Ctor } for B, Derived part
What's my mistake so that I'm getting "Base, default" instead of
"Base, Copy Ctor" in the 3 rd line of the Output?
thanks
m