c++ - How do you go about initializing all the objects by the constructor? -
this question has reply here:
what weird colon-member (“ : ”) syntax in constructor? 11 answershow go initializing objects constructor?
suppose have 4 set objects within location class. how initialize 4 set objects constructor set default? tried first create objects initialized :
set nyx (nyxv); , seek set within constructor, not work.
class location { public: vector<int> nyxv = { 0, 1, 2, 3, 4, 5}; vector<int> nyyv = { 0, 1, 2, 3, 4, 5 }; vector<int> sfxv = { 6, 7, 8, 9, 10 }; vector<int> sfyv = { 6, 7, 8, 9, 10 }; set nyx; set nyy; set sfx; set sfy; location(); ~location(); }; class set { public: set(vector<int> &); };
you should utilize initialization list:
location::location() : nyx(nyxv) {}
c++ oop constructor initialization
No comments:
Post a Comment