c++ - partial specialize template with template argument -


i have template

template <typename t, size_t maxsiz = 6> class array; 

and have adaptor template

template <typename t, template <typename> class container = std::vector> class stack; 

what want use array stack so

stack<int, array> s; 

however, default constructor of array not fulfill requirements made stack, need specialize stack array. ideally, want specialize ctor of stack<t, array>, can give inner array member right argument @ initialization.

i have tried this

template <typename t> class stack<t, array>::stack() : container(0) {  }  // container name of wrapped container 

it, however, has problems. first, wont compile (yeah...), , second, want able give array different size, this

stack<int, array<int, 13>> stack; 

or functionally equivalent (compile time constant size of array). how 1 accomplish this?

update

so i've done bit more digging, , apparently can't partially specialize member function without corresponding partial specialization of entire class. explains why attempt not work.

rather change stack work array, should provide adapter array works stack:

template <typename t> struct stackarray : array<t> {     stackarray()         : array<t>(0)     { }      // else needs change here }; 

that let do:

stack<int, stackarray> s; 

also, stack template incorrect. cannot use std::vector default template template <typename> class container std::vector takes two template arguments. more useful if made it:

template <typename t, typename container = std::vector<t>> struct stack { .. }; 

as add maxsiz argument stackarray , like:

stack<int, stackarray<int, 13>> s; 

this how std::priority_queue , std::stack designed.