Following is an interface:
class SIM{
private:
//private data
public:
Send();
Display();
Recieve();
Encrypt();
};
How do I restrict access to Display() function (it has to be lie in public part) of SIM to other classes except one class (Neo etc). I don’t want to use friend etc.
Edit:
I can move the display() to private , how do i allow only NEO class to access it? 0_o
You can have
Displaytake a dummy const reference to a type that can only be created from a privately nested within the class you want to be able to make the calls. Then in order to pass that type toDisplayyou have to be a member of that class.But why would you do that when
frienddoes exactly what you want?Code example: