在Visual Studio 2010/2011中缺少可变参数模板的情况下,仍然需要很多参数的构造函数。例如,以下内容将不会编译:
MyMaterials.push_back(std::make_shared<Material>(MyFacade,
name,
ambient,
diffuse,
specular,
emissive,
opacity,
shininess,
shininessStrength,
reflectivity,
bumpScaling,
maps,
mapFlags));
,因为它有13个参数,我认为make_shared从arg0限制为arg9。显而易见的解决方法是两部分构造,但我希望避免这种情况。除了使用new代替make_shared之外,这里还有其他可能性吗?
谢谢。
最佳答案
您可以使用构造一个类,然后将其移动到堆分配的值中。
MyMaterials.push_back(std::make_shared<Material>(
Material(MyFacade, name, ambient, diffuse, specular,
emissive, opacity, shininess, shininessStrength,
reflectivity, bumpScaling, maps, mapFlags)));
关于c++ - std::make_shared构造函数中的参数数量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10012345/