When coding classes that are tightly coupled functionally, but where you want a simple interface to the rest of the world, it would be neat if I could do something like this:
class log
{
private:
log_context& cont;
public:
create_log_section(std::string name)
{
cont.create_log_section(name);// this is fine! It's "internal"
cont.this_is_private(); // doesn't compile. Don't want anyone touching my privates!
}
};
class log_context
{
internal:
void create_log_section(std::string name);
private:
void this_is_private();
internal friend log; // Wow, possible?
}
Now, this would allow log to access the relevant parts of context, but not the private ones. The rest of the program should use log to add any context. It could also pass around strongly typed log_contexts between logs without having any extra power. I realize that this particular solution is not possible, but what are some common ones, if any?
You can use an internal class to do so
As internal as only private static functions, only its friends can access it