質問

Looking at A previous stack Question of std:make_shared vs std::shared_ptr, I have tried to implement this in a uni project. This was the previous 'question':

I can't think of any situation where

std::shared_ptr<Object> obj(new Object("foo", 1));

would be preferred to

auto obj = std::make_shared<Object>("foo", 1);

Thus I have taken this code:

std::shared_ptr<Triangle> pT1(new Triangle(pCanvas, 30, 30, 30, 60, 60, 30, 255, 0, 0));

And modified it to this code:

auto pT1 = std::make_shared<Triangle>(pCanvas, 30, 30, 30, 60, 60, 30, 255, 0, 0);

However, std::make_shared is underlined in red, and when I mouse-over it i get the error: "Error: no instance of overloaded function "std::make_shared" matches the argument list"

My code compiles and executes correctly with the first line of code, but if I use the second, there are some errors.

These errors are:

`1>------ Build started: Project: SIT153Canvas, Configuration: Debug Win32 ------ 1> main.cpp

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&,_V3_t &&,_V4_t &&)' : expects 5 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&,_V3_t &&)' : expects 4 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&,_V2_t &&)' : expects 3 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&,_V1_t &&)' : expects 2 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(_V0_t &&)' : expects 1 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

1>c:\users\steve\documents\visual studio 2012\projects\sit153canvas\main.cpp(54): error C2780: 'std::shared_ptr<_Ty> std::make_shared(void)' : expects 0 arguments - 10 provided

1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\memory(972) : see declaration of 'std::make_shared'

According to the error, std::make_shared seems to only expect a maximum of 5 arguments. Other websites I've searched unfortunately don't shed any light on the problem. Any help would be appreciated.

役に立ちましたか?

解決

VS2012 doesn't fully support variadic templates. There is no compiler support - instead, they are simulated in the library, up to 5 parameters by default. The actual number is determined by the macro _VARIADIC_MAX. Define it in your project properties to a sufficiently large value.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top