boost shared_ptr error

Hello people, here is the line and the associated error:
1
2
3
4
5
vector<boost::shared_ptr<line>> coordinates;
coordinates.resize(line_counter);
for (int i = 0; i<line_counter; ++i){
	coordinates[i] = boost::make_shared<boost::shared_ptr<line>>();
}

and
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1>c:\users\user\documents\visual studio 2012\projects\third\boost_1_53_0\boost_1_53_0\boost\smart_ptr\shared_ptr.hpp(601): error C2440: '<function-style-cast>' : cannot convert from 'boost::shared_ptr<T>' to 'boost::shared_ptr<T>'
1>          with
1>          [
1>              T=boost::shared_ptr<line>
1>          ]
1>          and
1>          [
1>              T=line
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous
1>          c:\users\user\documents\visual studio 2012\projects\third\third\dfx_reader.cpp(37) : see reference to function template instantiation 'boost::shared_ptr<T> &boost::shared_ptr<T>::operator =<boost::shared_ptr<T>>(boost::shared_ptr<boost::shared_ptr<T>> &&)' being compiled
1>          with
1>          [
1>              T=line
1>          ]
1>          c:\users\user\documents\visual studio 2012\projects\third\third\dfx_reader.cpp(37) : see reference to function template instantiation 'boost::shared_ptr<T> &boost::shared_ptr<T>::operator =<boost::shared_ptr<T>>(boost::shared_ptr<boost::shared_ptr<T>> &&)' being compiled
1>          with
1>          [
1>              T=line
1>          ]
1>c:\users\user\documents\visual studio 2012\projects\third\boost_1_53_0\boost_1_53_0\boost\smart_ptr\shared_ptr.hpp(601): error C2228: left of '.swap' must have class/struct/union


I am confused as to what I am doing wrong here, while googling similar questions it seems I may have ended up accidentally using different types of shared_ptrs here, but I don't see how... Please help :)
Also, is there a better way of initialising shared_ptrs?
the problem is on line 4:

coordinates[i] = boost::make_shared<boost::shared_ptr<line>>();

[EDIT]You can also write it like so:

coordinates[i].reset(new line());
Last edited on
Thank you very much! Can't believe I missed that! Also the alternative looks neater, thanks!
Topic archived. No new replies allowed.