I would like to define a pass-key class (/implement the pass-key idiom) that grants the code written in the body of ‘int main’ the ability to construct the pass-key.
The following is a working (Granting access to a class, “ToolMain.”) example of the pass-key class that I would like to grant ‘int main’ access to construct (Such as the class, “ToolMain,” has access to construct).
Can I ‘friend’ ‘int main,’ in this case?
class InputUpdateKey
{
private:
/**
* A friend of this class may access its private constructors.
*
* A class may permit a type (That is declared here as a friend)
* exclusive access to a method by including this class as a function argument.
*/
friend class ToolMain;
InputUpdateKey() {}
InputUpdateKey(const InputUpdateKey&) {}
InputUpdateKey& operator=(const InputUpdateKey&) = delete;
};
New contributor
Ahba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.