Limit on parameters made by boost make_shared
The following code snippet compiles without issue. In this case I am sending 9 parameters to make_shared
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
class Controller
{
int a1,a2,a3,a4,a5,a6,a7,a8,a9;
static void createInstance(int a1,
int a2,
int a3,
int a4,
int a5,
int a6,
int a7,
int a8,
int a9)
{
Controller::controller = boost::make_shared<Controller>(a1,a2,a3,a4,a5,a6,a7,a8,a9);
}
private:
Controller(int a1,
int a2,
int a3,
int a4,
int a5,
int a6,
int a7,
int a8,
int a9) { }
static boost::shared_ptr<Controller> controller;
};
int main()
{
Controller::createInstance(1,2,3,4,5,6,7,8,9);
}
The following code snippet does not compile. In this case I am sending 10 parameters to make_shared
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
class Controller
{
int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10;
static void createInstance(int a1,
int a2,
int a3,
int a4,
int a5,
int a6,
int a7,
int a8,
int a9,
int a10)
{
Controller::controller = boost::make_shared<Controller>(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
}
private:
Controller(int a1,
int a2,
int a3,
int a4,
int a5,
int a6,
int a7,
int a8,
int a9,
int a10) { }
static boost::shared_ptr<Controller> controller;
};
int main()
{
Controller::createInstance(1,2,3,4,5,6,7,8,9,10);
}
When trying to compile
I am getting the following error:In static member function ‘static void Controller::createInstance(int, int, int, int, int, int, int, int, int, int)’:
error: no matching function for call to ‘make_shared(int,int,int,int,int,int,int,int,int,int)’
Why does make_shared have this conditional limit of 9 parameters? How to take more than 9 parameters?
+3
source to share
1 answer
Your compiler and / or library doesn't seem to support variadic templates.
If you want this syntax to work, you can switch to a variadic compiler and use the stl function std :: make_shared
+1
source to share