potential linkage circular dependencies? (maybe slightly OT)

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)?
 
V

Victor Bazarov

Anonymous said:
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?

Shouldn't be a problem. Unresolved references are only caused when
the functions needed are not present. If you let the linker know where
to find all the functions, it will.
if I have reason to worry though (for the above reasons), then [..]

There is no reason to worry.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top