3

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!

vexator
  • 427
  • 1
  • 7
  • 16

1 Answers1

2

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

highBandWidth
  • 16,751
  • 20
  • 84
  • 131
Carsten Greiner
  • 2,928
  • 2
  • 16
  • 20
  • i did, to no avail. I should point out that it works just fine with other classes and that I declare the following in a common header file: **using boost::shared_ptr; using boost::make_shared;** – vexator Dec 02 '11 at 14:10
  • did u try removing the using boost::make_shared and then use in the code auto portal = boost::make_shared ... ? – Carsten Greiner Dec 02 '11 at 15:51
  • 1
    **yeah that did it, thanks!** now, can I somehow "un-use" std::make_shared so that I don't have to specify which namespace's template to use? Also, I'm still not sure why this happens to this class but not the other +50 classes in my project. They all share the same base header. – vexator Dec 02 '11 at 16:56
  • Or, is it advisable to simly rely on MS's implementation of shared_ptr? – vexator Dec 02 '11 at 17:02
  • 1
    @Vexator: Simple: *Do not use `using namespace std;`*, especially not in a header. Typing 5 more characters is really no trouble, especially so if it saves you from such ambiguities. – Xeo Dec 02 '11 at 19:44