
Originally Posted by
Ajay Vijay
Well, the class itself is assigning "rights" to other class (or function).
What I explained was "denying" everyone to create stack instance.
You are absolutely right. I just wanted to show how it is possible using friend classes i.e. "denying everyone other than friends". There is even one non-standard way too, you can compile this code in even VC 2008, but again it is non-standard.
Code:
template <typename T>
class PrivateDtor
{
private:
PrivateDtor()
{
std::cout << "PrivateDtor::PrivateDtor" << std::endl;
}
~PrivateDtor()
{
std::cout << "PrivateDtor::~PrivateDtor" << std::endl;
}
friend typename T;
};
class FriendClass
{
private:
PrivateDtor<FriendClass> m_objPrivateDtor;
};
Here "friend typename T;" is a non standard way.