由升压采取限参数make_shared [英] limit on parameters taken by boost make_shared

查看:107
本文介绍了由升压采取限参数make_shared的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code的一块编译没有问题。在这种情况下我送9参数make_shared

The following piece of code compiles without an issue. In this scenario I'm 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);
}

以下code的一块不能编译。在这种情况下我送10的参数make_shared

The following piece of code does not compile. In this scenario I'm 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);
}

在编译的时候我收到以下错误

I get the following error when trying to compile

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)’

为什么make_shared有9个参数此arbitary限制?我怎么会超过9参数?

Why does make_shared have this arbitary limit of 9 parameters? How do I take more than 9 parameters?

推荐答案

您的编译器和/或库似乎不支持可变参数模板。

Your compiler and/or library doesn't seem to support variadic templates.

如果您想要这个语法来工作,你可能要升级到支持可变参数模板,并使用STL函数的的std :: make_shared

If you want this syntax to work, you may want to upgrade to a compiler that support variadic template and use the stl function std::make_shared

这篇关于由升压采取限参数make_shared的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆