Hi,
I realize that there are a lot of questions regarding friend classes in C++. My question, though, is tied to a specific scenario. Given the below code, is it appropriate to use friend in such a manner?
class Software
{
friend class SoftwareProducer;
SoftwareProducer* m_producer;
int m_key;
// Only producers can produce software
Software(SoftwareProducer* producer) : m_producer(producer) { }
public:
void buy()
{
m_key = m_producer->next_key();
}
};
class SoftwareProducer
{
friend class Software;
public:
Software* produce()
{
return new Software(this);
}
private:
// Only software from this producer can get a valid key for registration
int next_key()
{
return ...;
}
};
Thanks,
Best regards,