马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
类模板=>实力化=>模板类
通过类模板实现栈,点击查看代码[code]#include #include using namespace std;template//template 也可以这样写,写个默认类型//这是个模板名称 ,模板名称+类型参数列表=类名称class MyStack {public: //在构造和析构函数名字后面可以不加 MyStack(int _size = 10) : size(_size), top(-1), pHead(new T[size]) { } //拷贝构造 MyStack(const MyStack & src) : top(src.top), size(src.size) { pHead = new T[size]; for (int i = 0; ipHead = tepPHead; }};templatevoid MyStack::Test()const { cout |