Sunday, 15 February 2015

c++ - member variable default initialization template -



c++ - member variable default initialization template -

iam using non c++11 capable compiler not back upwards default initialization on class declaration.

since have class manages visualization , contains tons of bool flags , other fellow member write template class default init.

i implement like:

template <unsigned int i> class uintdef{ public: uintdef(unsigned int d=i):i(d){ cout << "init i="<<d<<endl; } operator unsigned int&(){return i;} unsigned int i; };

or

template <bool i> class booldef{ public: booldef(bool d=i):i(d){ cout << "init i="<<d<<endl; } operator bool&(){return i;} bool i; };

but utilize type template parameter

template <type t, t i> class def{ public: def(t d=i):i(d){ cout << "init i="<<d<<endl; } operator t&(){return i;} t i; };

obviously lastly illustration not work. there way accomplish or exist this?

your syntax in template parameter list wrong:

template <typename t, t i> // ^^^^

apart that, code right - here demo.

c++

No comments:

Post a Comment