c++11 - Dynamic array inside of Class template -
i have want make template class vector , parameters should type , length of dynamic array thats in it.
template < class type, int length > class vektor { public: int count; int currentpos; type* beginning = new type[count]; int lastatuse=0; vektor() { count = length; } void pushback(type a) { beginning[lastatuse]=a; lastatuse++; } void insert(type a, int position) { beginning[position] = a; } };
i tried test in main , getting error:
error c2440: 'initializing' : cannot convert 'iterator_traits<_iter>::difference_type (__cdecl *)(_init,_init,const _ty &)' 'unsigned int'
can me find i'm doing wrong ?
here:
type* beginning = new type[count]; ^
you have count
, not count
also, count
not yet set when new
executes, should move constructor here:
vektor() { count = length; beginning = new type[count]; }
Comments
Post a Comment