Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用父类中的变量_C++_Templates_Inheritance_Dependent Name - Fatal编程技术网

C++ 使用父类中的变量

C++ 使用父类中的变量,c++,templates,inheritance,dependent-name,C++,Templates,Inheritance,Dependent Name,我一直在尝试使用模板来实现堆栈。我的问题是在这种情况下如何使用父类中的变量 在这种情况下,我的编译错误是:“top,a,size”未在此范围内声明 template<class T> class buffer { public: T *a; int top,i,size; }; template<class T> class Queue:

我一直在尝试使用模板来实现堆栈。我的问题是在这种情况下如何使用父类中的变量

在这种情况下,我的编译错误是:“top,a,size”未在此范围内声明

    template<class T>
        class buffer
        {
  public:
            T *a;
            int top,i,size;
        };

    template<class T>
        class Queue: public buffer<T>
        {
    public:
            Queue(int siz)
            {
                a=new T[siz];
                size=siz;
                top=-1;
            }
            void push(T ele)
            {
                if(top!=size-1){a[++top]=ele;} 
            }

            T pop()
            {
                  return(a[top--]);
            }

            void print()
            {
                for(i=0;i<top;i++)
                    cout<<" "<<a[i];

                cout<<endl;
            }
        };
模板
类缓冲区
{
公众:
T*a;
int-top,i,大小;
};
模板
类队列:公共缓冲区
{
公众:
队列(整数大小)
{
a=新的T[siz];
尺寸=尺寸;
top=-1;
}
无效推力(T ele)
{
如果(top!=size-1){a[++top]=ele;}
}
T pop()
{
返回(a[顶部--]);
}
作废打印()
{

对于(i=0;i要使它们成为依赖名称,您必须先使用
this->
buffer::

所以


它为我编译,您在这里使用的是什么其他代码?
i
应该是局部变量而不是成员。顺便说一句,您的继承很奇怪……您不遵守3/5/0规则。@meneldal我想真正的问题是您使用的是哪个MSVC版本;)
this->a = new T[siz];
this->size = siz;
this->top = -1;