Boost logo

Boost Users :

Subject: Re: [Boost-users] Cyclic includes when using smart pointers.
From: Jared Lee Richardson (jaredr26_at_[hidden])
Date: 2009-03-31 12:25:23


Oh ok, now I feel dumb. :(

I thought that because it was a template, I couldn't forward declare
it because the template would need information about the class.

I might still have some issues when I start inlining, but I should be
able to work around them.

Jared

On Tue, Mar 31, 2009 at 9:12 AM, Peter Dimov <pdimov_at_[hidden]> wrote:
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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