问题描述
我有以下4个文件:
1. arrayListType.h:声明并定义arrayListType类作为模板
2. unorderedArrayListType.h:继承自arrayListType类和Declares并定义unorderedArrayListType作为模板。
3. main1.cpp:测试程序以测试unorderedArrayListType类。
4. Makefile
I have the following 4 files:
1. arrayListType.h: Declare and define arrayListType class as a template
2. unorderedArrayListType.h: Inherited from arrayListType class and Declares and defines unorderedArrayListType as a template.
3. main1.cpp: Test program to test unorderedArrayListType class.
4. Makefile
我得到一个编译错误,当访问arrayListType的受保护的变量在unorderedArrayListType例如:length not declaration in this scope,list未声明在此范围,其中length和list是arrayListType类中的受保护的变量。
I get a compile error saying when accessing the protected variables of arrayListType in unorderedArrayListType for example: "length not declared in this scope", "list not declared in this scope", where length and list are protected variables in arrayListType class.
以下是代码:
arrayListType.h
The following are the codes:
arrayListType.h
c>One way, using this-> before all the inherited names: this->list, this->length.
另一种方式,使用声明:使用arrayListType< elemType> :: length; 在导出类的私有部分)。
Another way, using declarations: using arrayListType<elemType>::length; etc (for example in the private section of the derived class).
这是一个FAQ条目:
A FAQ entry on this: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19
这篇关于templates:父类成员变量在继承类中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!