c++ - 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 initialize affordable empty list without constructor } } trying initialize list parameter reference. how can this?
use 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>{}; } } fyi, c++ literally built on constructors. come eventually, , they're quite helpful.
Comments
Post a Comment