Can we avoid the constructor of the base class being called by the derived class?
#include <iostream>
using namespace std;
class BaseClass {
public:
BaseClass(){
cout<<"Parent Class\n";
}
};
class DerivedClass: private BaseClass{
public:
DerivedClass() {
cout<<"Child Class";
}
};
int main() {
DerivedClass obj = DerivedClass();
return 0;
}
The output is
Parent Class
Child Class
But I don’t want “Parent Class” to be chosen.