Initialization list c++ with complex parameter -


i've got class:

class foo { private:   other bar; }; 

and other class:

class other { public: other(std::list<int> l, ...other parameters...); }; 

other doesn't have default contructor , can't add it. how can initialize attribute bar? mean need create list, need add item , on, it's difficult use initialization list because need write code fill list. how can do? think can use pointer instead, i'd avoid dynamic allocation.

you write function create object, , use in initialiser list:

static other make_bar() {     std::list<int> l;     // fill list, whatever else need     return other(l, ...); }  foo() : bar(make_bar()) {} 

or use boost::optional defer initialisation without requiring dynamic allocation.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -