Smart pointer and cyclic dependencies

M

Marcel Müller

Hi,

I have the problem that two types have smart pointers that point on each
other. The smart pointers are similar to boost::intrisive_ptr and
boost::scoped_ptr, but not identical, because the the platform is too
old for the boost libraries to compile. Unfortunately my implementations
requires T to be a complete type.

The boost documentation says the T need not to be a complete type unless
you instantiate the smart pointer. How did they do the trick? I found no
hint in the boost documentation.


class B;

class A
{
scoped_ptr<B> b;
//...

};

class B
{
intrusive_ptr<A> a;
//...

};


Is there a solution for the above dependency other than turning b into
an ordinary pointer and emulating the smart pointer in the functions of A?
 
M

Marcel Müller

Marcel said:
class B;

class A
{
scoped_ptr<B> b;
//...

};

class B
{
intrusive_ptr<A> a;
//...

};


Is there a solution for the above dependency other than turning b into
an ordinary pointer and emulating the smart pointer in the functions of A?

Forget about the question. It turned out to be a compiler problem of IBM
Visual Age C++ 3.08 (quite old). Most probably the rule to get this
working was not yet part of the C++ standard when then compiler was
built in mid 90's.

When the member functions of scoped_ptr or intrusive_ptr are defined
inside the class body the compilation fails. It the functions are
defined immediately behind the class body with
template <class T>
inline ...
everything is fine. So my implementations of the smart pointers do not
depend on a complete type at the declaration as well.


Marcel
 

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,777
Messages
2,569,604
Members
45,222
Latest member
patricajohnson51

Latest Threads

Top