I have two classes ( A
and B
)
I need to do something that when I make an object of class A (i.e. A obj()
) a vector of class B that points to the objects of class A
be constructed.
i.e.
if I make an object of class A
named obj()
, then I want the first element of vector in class B (i.e. vector<'A*'> objects
) to be declare by obj()
.
objects[0] = obj()
The code:
class B;
class A
{
public:
A(int _location)
{
location = _location;
pointer_B->redefine(this); // here in this line(14) I get two errors
}
private:
int location;
B* pointer_B;
};
class B
{
public:
void redefine(A* cur_obj)
{
objects.push_back(cur_obj);
}
private:
vector<A*> objects;
};
the errors are:
use of undefined type B (line 14)
left of '->redefine' must point to class/struct/union/generic type (line 14)