Boost logo

Boost Users :

Subject: Re: [Boost-users] Cyclic includes when using smart pointers.
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-03-31 12:12:16


Jared Lee Richardson:
...
> I have the following situation, simplified down.
>
> Header file 1:
>
> class Test1
> {
> vector<Test2Ptr> mTest2Objects;
> };
>
> typedef boost::shared_ptr<Test1> Test1Ptr;
>
>
> Header file 2:
>
> class Test2
> {
> vector<Test1Ptr> mTest1Objects;
> };
>
> typedef boost::shared_ptr<Test2> Test2Ptr;
>
> Now normally I'd get around this easily by doing a forward
> declaration, but I can't do that with a smart pointer definition.

Why not? With raw pointers you'd do:

class Test2;

class Test1
{
    vector<Test2*> mTest2Objects;
};

With shared_ptr you do

class Test2;

class Test1
{
    vector< shared_ptr<Test2> > mTest2Objects;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net