#include<iostream> #include<vector> #include<list> template<typename T, int MAXSIZE> class MyContainer { public: MyContainer(){ std::cout<<MAXSIZE<<std::endl; } int capacity() const { return MAXSIZE; } private: T elements[MAXSIZE]; }; // 和普通类型模板一样,非类型模板参数也可以有缺省值,如: template<typename T, int MAXSIZE = 10> class MyContainer2 { public: MyContainer2(){ std::cout<<MAXSIZE<<std::endl; } int capacity() const { return MAXSIZE; } private: T elements[MAXSIZE]; }; int main() { MyContainer<int,50> c1; MyContainer2<int> c2; return 0; }
非类型模板参数
猜你喜欢
转载自javaeye-hanlingbo.iteye.com/blog/2407856
今日推荐
周排行