Friendship isn't inherited.
You declared a private constructor for the Lock class, in which it is only accessible either within that class or within a scope that has the right to access that Constructor.
Also because you've defined a constructor there is no default/dummy constructor provided.
Because First is a friend of Lock, First has the right to access Lock's private constructor.
Second does not inherit friendship of Lock despite the fact that Second derives from First.
In order to make the code work, you'll have to make Lock declare Second as a friend also--
#include <iostream>
using namespace std;
class Lock
{
friend class First;
friend class Second;
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();
cin.get();
return 0;
}