I have two classes A, B of which I want to create the object of class B from class A only. I do not want other classes to create an object of the class B. Here is the code snippet. Any suggestion how can I achieve without nested class? Can somebody please advice what is the correct approach to solving this problem?
class B
{
public:
B(int x1, int y1, int x2, int y2);
~B();
updateCoordinates(int x1, int y1, int x2, int y2);
private:
int x1;
int y1;
int x2;
int y2;
};
class A
{
public:
A(int mode);
~A();
private:
vector<B> bList;
};
A::A()
{
// Based on the value of mod, create
// objects of B and add to bList
}