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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -