#include <iostream>
using namespace std;
class Lock
{
friend class First;
private:
Lock()
{
}
};
class First : virtual public Lock
{
public:
void function()
{
cout << "function1" << endl;
}
};
class Second: public First
{
public:
void function2()
{
cout << "function2" << endl;
}
};
int main()
{
First f;
f.function();
Second s;
s.function2();
}
Error:
classVirtDer.cpp(39) : error C2248: 'Lock::Lock' : cannot access private member declared in class 'Lock'
classVirtDer.cpp(9) : see declaration of 'Lock::Lock'
classVirtDer.cpp(6) : see declaration of 'Lock'
This diagnostic occurred in the compiler generated function 'Second::Second'
But when i remove the class Second, it works fine. Can someone explain?