使用std时候遇到的问题
先谢谢各位,一直以来在CSDN上受到帮助。
写个栈的类模板
//stack.h
#ifndef _STACK_TTTT_H_
#define _STACK_TTTT_H_
namespace cpp3
{
#include <string.h>
//#include <iostream>
//using namespace std;
template <class Type>
class Stack
{
int stackLarger;
int num;
Type * pS;
public:
Stack(int large=50);
bool initial();
bool push(Type &);
bool pop(Type &);
bool pop();
bool isEmpty();
~Stack();
};
template <class Type>
Stack<Type>::Stack(int large)
{
stackLarger=large;
num=0;
pS=NULL;
}
template <class Type>
bool Stack<Type>::initial()
{
pS=new Type[stackLarger];
if(pS==NULL)
return false;
return true;
}
template <class Type>
bool Stack<Type>::push(Type & t)
{
if (stackLarger==num)
return false;
memcpy((void *)(pS+stackLarger-num-1),&t,sizeof(Type));
num++;
return true;
}
template <class Type>
bool Stack<Type>::pop(Type & t)
{
if (num==0)
return false;
memcpy(&t,(void *)(pS+stackLarger-num),sizeof(Type));
num--;
return true;
}
template <class Type>
bool Stack<Type>::pop()
{
if (num==0)
return false;
num--;
return true;
}
template <class Type>
bool Stack<Type>::isEmpty()
{
return (bool)num;
}
template <class Type>
Stack<Type>::~Stack()
{
if(pS!=NULL)
{
//if (num!=0)
// throw std::runtime_error("The stack is not empty,it will be error when the stack has the member of point!please check it again.");
delete pS;
}
}
}
#endif
1:想在~Stack中使用抛异常,但是一写就报错,参见注释掉的这几行:
//#include <iostream>
//using namespace std;
//if (num!=0)
// throw std::runtime_error("The stack is not empty,it will be error when the stack has the member of point!please check it again.");
2:使用以下方式包含上面的模板类后的问题
#include "Stack\stack.h"
using namespace cpp3;
在main中使用的时候
Stack<int> p;
VC6.0下p后面只能点出私有成员列表,却点不出成员函数列表,不知道是我写得问题大还是VC有问题?