Tuesday, 15 April 2014

c++ - How to initialise vector member variable in constructor of class template -



c++ - How to initialise vector member variable in constructor of class template -

i'm trying initialise vector fellow member variable in constructor of class template. i'm getting "'t' not refer value" error compiler, because t refers class, can't want format. what's right format here constructor please? (i'm guessing need convert t const val_type, per constructor?)

template <class t> class peripheralsystem { public: peripheralsystem(uint32_t numperipherals = 0) : peripherals(numperipherals, t) {}; virtual ~peripheralsystem(); private: std::vector<t> peripherals; };

if intent vector have initial size of numperipherals elements, use

peripheralsystem(uint32_t numperipherals = 0) : peripherals(numperipherals) {};

now peripherals have numperipherals value-initialized (which default initialization if t class type) instances of t.

c++ templates vector constructor stl

No comments:

Post a Comment