Private aggregate initialization

元气小坏坏 提交于 2021-02-20 19:02:13

问题


Is it possible to define as private the aggregate initialization for an aggregate class? I would like that the class can only be aggregate-initialized by its own static private members.

Example:

struct Size
{
    const unsigned int width;
    const unsigned int height;

    static const Size big;
    static const Size small;

private:

    Size( ) = default;

    // something to declare the aggregare initialization as private
};

const Size Size::big = { 480, 240 };
const Size Size::small = { 210, 170 };

来源:https://stackoverflow.com/questions/35793085/private-aggregate-initialization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!