Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'boost::make_shared' : ambiguous call to overloaded function

I've got the following class definition:

class Portal
{
   public:

   Portal( const vector<vec3> &vertices, shared_ptr<Sector> target );

   ...
};

Somewhere else, I want to create an instanceof said class like this:

auto portal = make_shared<Portal>( portalVertices, target );

However, I get the following error message in Visual Studio 2010:

error C2668: 'boost::make_shared' : ambiguous call to overloaded function

Can anyone tell me why? I only define a single constructor. Thank you!

like image 774
vexator Avatar asked Apr 16 '26 01:04

vexator


1 Answers

As you are using the keyword auto I assume you are using C++11 features. C++11 also comes with std::make_shared.

So, please try adding the namespace:

auto portal = std::make_shared<Portal>( portalVertices, target );

or

auto portal = boost::make_shared<Portal>( portalVertices, target );

So what I usually do in my code / the .C file is:

using namespace std; // this is a "using" directive
....
void somefunction() {
    auto portal = make_shared<Portal>( ... );
}

As you mentioned you were specifying in your header

using boost::make_shared;

I would really like to see the full header file. As I think you actually wanted to have a using directive, but ended up in having a using declaration.

Have a look at this description:

using directive: http://msdn.microsoft.com/en-us/library/aewtdfs3%28v=vs.80%29.aspx

using declaration: http://msdn.microsoft.com/en-us/library/was37tzw%28v=vs.80%29.aspx

like image 69
Carsten Greiner Avatar answered Apr 18 '26 23:04

Carsten Greiner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!