在模板和继承的C ++中使用未声明的标识符 [英] Use of undeclared identifier in C++ with templates and inheritance
本文介绍了在模板和继承的C ++中使用未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码无法编译 - 使用未声明的标识符。我使用GCC和XCode进行编译。
The following code cannot compile - use of undeclared identifier. I use GCC and XCode for compilation.
一切都在一个头文件中。
Everything is in a single header file.
include "MyArray.h"
template <typename T>
class MyBase {
public:
MyBase();
virtual ~MyBase();
void addStuff(T* someStuff);
protected:
MyArray<T*> stuff;
};
template <typename T>
MyBase<T>::MyBase() {}
template <typename T>
MyBase<T>::~MyBase() {}
template <typename T>
void MyBase<T>::addStuff(T* someStuff) {
stuff.add(someStuff);
}
// ---------------------
template <typename T>
class MyDerived : public MyBase<T> {
public:
MyDerived();
virtual ~MyDerived();
virtual void doSomething();
};
template <typename T>
MyDerived<T>::MyDerived() {}
template <typename T>
MyDerived<T>::~MyDerived() {}
template <typename T>
void MyDerived<T>::doSomething() {
T* thingy = new T();
addStuff(thingy); //here's the compile error. addStuff is not declared.
}
有没有人有解释?
提前感谢!
Does anyone have an explanation? Thanks in advance!
推荐答案
试用
this->addStuff(thingy);
这篇关于在模板和继承的C ++中使用未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文