从引用参数将对象初始化为空列表

Initializing object to an empty list from a reference parameter

class ListOfGifts
{
   private:
       Gift list[50];
       int count = 0;

   public:
       void suggest(ListOfGifts& affordable, float dollarLimit) const
       {
            // how do I initialize affordable to an empty list without a constructor
       }

}

正在尝试从作为引用的参数初始化列表。我该怎么做?

使用 std::array:

class ListOfGifts
{
   private:
       std::array<Gift, 50> list;
       int count = 0;

   public:
       void suggest(ListOfGifts& affordable, float dollarLimit) const
       {
            affordable.list = std::array<Gift, 50>{};
       }

}

仅供参考,C++ 实际上是 构建 构造函数。他们最终会出现,而且他们实际上很有帮助。