A
Anonymous
I am working on a suite of existing libraries and I anticipate a future
problem. the problem (as i see it), arises as a result of the following:
There is a class A that resides in librray A, and class B that resides
in library B.
class B is declared as ff:
class B
{
public:
B();
set_parent(A* a);
B(const B& b);
B& opeartor=(const B& b);
~B();
private:
A * m_parent ;
};
the requirement is that class B can make calls back into the parent,
(when the ptr is non-null)
class A has a method foobar, implemented as ff:
A::foobar()
{
B * b = new B();
//assume no error for sake of brevity
b->set_parent(this);
//do something with b
}
As it stands, my current understanding is that library A will need to
link into library B (and vice versa) - I think this will end in
unresolved references. can any one assure me that my worries are unfounded?
if I have reason to worry though (for the above reasons), then could
anyone suggest a way where I can have the desired behaviour -
i). A can create an instance of B, set itself as parent
ii). B can call back into its parent (if non null)
SUBJECT to the requirement that A and B are in different translation
units (or more specifcally, different libraries)?
problem. the problem (as i see it), arises as a result of the following:
There is a class A that resides in librray A, and class B that resides
in library B.
class B is declared as ff:
class B
{
public:
B();
set_parent(A* a);
B(const B& b);
B& opeartor=(const B& b);
~B();
private:
A * m_parent ;
};
the requirement is that class B can make calls back into the parent,
(when the ptr is non-null)
class A has a method foobar, implemented as ff:
A::foobar()
{
B * b = new B();
//assume no error for sake of brevity
b->set_parent(this);
//do something with b
}
As it stands, my current understanding is that library A will need to
link into library B (and vice versa) - I think this will end in
unresolved references. can any one assure me that my worries are unfounded?
if I have reason to worry though (for the above reasons), then could
anyone suggest a way where I can have the desired behaviour -
i). A can create an instance of B, set itself as parent
ii). B can call back into its parent (if non null)
SUBJECT to the requirement that A and B are in different translation
units (or more specifcally, different libraries)?