How can instantiate this template struct?
template<typename T,
template<typename, template <typename> class D= std::allocator
>class Z=std::vector
>
struct amen
{
Z<T,D<T> >开发者_开发技巧; cc; // i know D template class parameter is not visible , how do i do it?
};
int main(){
amen<int> moreAmen;
}
Can anyone show me how to do it?
You have this wrong. It should be
template<typename U, typename D = std::allocator<U>
> class Z = std::vector
The allocator of std::vector
is not a template. Then the declaration of cc
becomes
Z<T> cc;
As you gave a default argument for the allocator, you don't need to pass any argument for it. If you wanted to, you would need to pass std::allocator<T>
or some other allocator again
Z<T, std::allocator<T> > cc;
// or T<T, my::funny:allocator> cc;
The default argument of a parameter of a template template argument is not "inherited" to the corresponding template template parameter of your class/struct template. You need to specify it again, like above (by stating std::allocator<U>
as default template argument).
精彩评论