为什么qsize没有被linkquene继承?


#include<iostream>
#include<assert.h>
using namespace std;

template <class type>
class abque{
    public:
        bool IsEmpty()
        {
            return (qsize==0)? true:false;
        }
        virtual void PushTail(type &)=0;
        virtual bool PopHead(type &)=0;
        virtual void Clear()=0;
    protected:
        int qsize;
};

template <class type>
class quenenode{
    public:
        type data;
        quenenode* next;
};

template <class type>
class linkquene:public abque<type>{
    public:
        linkquene();
        linkquene(linkquene &q)
        {
            head=NULL;
            tail=NULL;
            Copy(q);
        }
        ~linkquene()
        {
            Clear();
        }
        void PushTail(type &);
        bool PopHead(type &);
        void Clear();
        linkquene& operator=(linkquene &q)
        {
            Copy(q);
            return *this;
        }
    protected:
        quenenode<type> *head;
        quenenode<type> *tail;
        linkquene &Copy(linkquene &q);
};

template<class type>
linkquene<type>::linkquene()
{
    qsize=0;
    head=tail=NULL;    
};

template<class type>
void linkquene<type>::PushTail(type & x)
{
    quenenode<type>* p;
    p=new quenenode<type>;
    assert(p);
    if(p==NULL)
    {
        cout<<"out of memory"<<endl;
        exit(1);
    }
    p->data=x;
    if (tail)
    {
        p->next=NULL;
        tail->next=p;
        tail=p;
    }
    else
    {
        p->next=NULL;
        tail=p;
        head=p;
    }
    qsize++;
};

template<class type>
bool linkquene<type>::PopHead(type &x) 
{
    quenenode<type> *p;
    if (head)
    {
        x=head->data;
        p=head;
        head=head->next;
        if(head==NULL)
        {
            tail=NULL;
        }
        delete p;
        qsize--;
        return true;
    }
    return false;
}

template<class type>
linkquene<type> &linkquene<type>::Copy(linkquene<type> &que)
{
    quenenode<type> *p,*q,*r;
    if (head)
        Clear();
    qsize=que.qsize;
    head=tail=NULL;
    if (!que.head)
        return *this;
    head= new quenenode<type>;
    assert(head);
    if (head==NULL)
    {
        cout<<"out of memory"<<endl;
        exit(1);
    }
    head->data=(que.head)->data;
    head->next=NULL;
    tail=head;
    r=NULL;
    p=head;
    q=que.head->next;
    while(q)
    {
        r=new quenenode<type>;
        assert(r);
        if (r==NULL)
        {
            cout<<"out of memory"<<endl;
            exit(1);
        }
        r->data=q->data;
        r->next=NULL;
        p->next=r;
        tail=r;
        p=p->next;
        q=q->next;
    }
    return *this;
}

template<class type>
void linkquene<type>::Clear()
{
    type p;
    while(PopHead(p));
    head=tail=NULL;
}

int main()
{
    int n,i,x;
    linkquene<int> quene1,quene2,quene3;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if (x<60) quene1.PushTail(x);
        if (x>=60&&x<100) quene2.PushTail(x);
        if (x>=100) quene3.PushTail(x);
    }
}

为什么qsize没有被linkquene继承?如果在linkquene中重新定义一个qsize,就没有问题了。

两阶段名称查找。第一阶段模板类未被创建,所以找不到基类的成员,报错,第二阶段,类型确定,模板类建出来了,找到了,就好了。

//延迟到第二阶段查找
 abque<type>::qsize;
//或者
this->qsize;

《C++编程思想》