linker error

写了个程序分为三个文件SeqStack.h(顺序栈),MembFunction.cpp(成员函数),Main.cpp编译时提示

例如  [Linker error] undefined reference to `SeqStack<int>::IsEmpty() const'

#include"SeqStack.h"
#include<iostream>
using namespace std;
int main()
{
    SeqStack<int> sstack;
    int ival=0;
    while(cin>>ival)
    sstack.Push(ival);
    system("pause");
    return 0;
}

 

#include"SeqStack.h"
#include<stdexcept>
#include<iostream>
using namespace std;
//pop,push
template<class T>
void SeqStack<T>::Push(const T& tobj)
{
     if(IsFull())
     OverFlow();
     *top=tobj;
     ++top;
}
template<class T>
void SeqStack<T>::Pop()
{
     if(IsEmpty())
     throw runtime_error();
     T* tmp=top;
     --top;
     delete tmp;
}
//isfull,empty
template<class T>
bool SeqStack<T>::IsFull()const
{
     if(top==data+length)
     return true;
}
template<class T>
bool SeqStack<T>::IsEmpty()const
{
     if(top==data)
     return true;
}
//size
template<class T>
unsigned int SeqStack<T>::Size()
{
         return top-data+1;
}
//gettop
template<class T>
T& SeqStack<T>::GetTop()const
{
   return *top;
}
//overflow
template<class T>
void SeqStack<T>::OverFlow()
{
     throw runtime_error("stack is full");
}
//purge
template<class T>
void SeqStack<T>::Purge()
{
     while(top!=data-1)
     {
                       T* tmp=top;
                       --top;
                       delete tmp;
     }
}


#ifndef SEQSTACK_H
#define SEQSTACK_H
#include<iostream>
template<class T>
class SeqStack
{
      protected:
                T* data;
                T* top;
                unsigned int length;
      public:
             SeqStack(unsigned int _length=5):data(new T[_length]),top(data),length(_length){}
             ~SeqStack(){delete [] data;}
             void OverFlow();
             void Push(const T&);
             void Pop();
             T& GetTop()const;
             bool IsEmpty()const;
             bool IsFull()const;
             unsigned int Size();
             void Purge();            
};
#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值