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
}
}
尝试从作为参考的参数初始化列表。我怎么能这样做?
答案 0 :(得分:2)
使用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 ++在构造函数上实际上是构建的。他们最终会出现,他们实际上非常有帮助。