简体   繁体   中英

std::make_shared number of parameters in the constructor

In the absence of variadic templates (still,) in Visual Studio 2010/2011. a constructor that takes a lot of parameters can be problematic: For example the following won't compile:

    MyMaterials.push_back(std::make_shared<Material>(MyFacade,
                                                     name,
                                                     ambient,
                                                     diffuse,
                                                     specular,
                                                     emissive,
                                                     opacity,
                                                     shininess,
                                                     shininessStrength,
                                                     reflectivity,
                                                     bumpScaling,
                                                     maps,
                                                     mapFlags));

, because it has 13 parameters and I think make_shared is limited from arg0 to arg9. The obvious work-around is two part construction, but I was hoping to avoid this. Is there any other possibility here, apart from use of new instead of make_shared?

Thanks.

You can use construct a class which will then be moved into the heap allocated value.

MyMaterials.push_back(std::make_shared<Material>(
    Material(MyFacade, name, ambient, diffuse, specular, 
             emissive, opacity, shininess, shininessStrength, 
             reflectivity, bumpScaling, maps, mapFlags)));

you can create a "input struct" with all the relevant members.
fill it with the correct values and call the constructor with that as his only param.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM