#include<iostream> using namespace std; class Base; class final_lock { friend class Base; private: final_lock() {} final_lock(const final_lock&) {} }; class Base : public virtual final_lock { ///// Here virtual is necessary... why is it so? How does it make any difference internally? public: Base() { } Base(char*) {} void fun(){ cout<<"I am in base"<<endl; } }; class Der : public Base { }; int main() { ///Der dd; // Cannot construct a Der obj... why it it so? ///dd.fun(); Base m; }
#include<iostream> using namespace std; class Base; class final_lock { friend class Base; private: final_lock() {} final_lock(const final_lock&) {} }; class Base : public final_lock { //// Here virtual is not present. public: Base() { } Base(char*) {} void fun(){ cout<<"I am in base"<<endl; } }; class Der : public Base { }; int main() { Der dd; /// Here we can construct a Der obj!!!!! dd.fun(); Base m; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)