template <typename T>
class MyBase {
public:
MyBase();
virtual ~MyBase();
void addStuff(T* someStuff);
protected:
T* stuff;
};
template <typename T>
MyBase<T>::MyBase() {}
template <typename T>
MyBase<T>::~MyBase() {}
template <typename T>
void MyBase<T>::addStuff(T* someStuff) {
stuff = 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.
}
int main() {
MyDerived<int> m;
m.doSomething();
}
dGVtcGxhdGUgPHR5cGVuYW1lIFQ+CmNsYXNzIE15QmFzZSB7CnB1YmxpYzoKICBNeUJhc2UoKTsKICB2aXJ0dWFsIH5NeUJhc2UoKTsKICB2b2lkIGFkZFN0dWZmKFQqIHNvbWVTdHVmZik7CnByb3RlY3RlZDoKICBUKiBzdHVmZjsKfTsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpNeUJhc2U8VD46Ok15QmFzZSgpIHt9CnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpNeUJhc2U8VD46On5NeUJhc2UoKSB7fQoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnZvaWQgTXlCYXNlPFQ+OjphZGRTdHVmZihUKiBzb21lU3R1ZmYpIHsKICBzdHVmZiA9IHNvbWVTdHVmZjsKfQoKLy8gLS0tLS0tLS0tLS0tLS0tLS0tLS0tCgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4KY2xhc3MgTXlEZXJpdmVkIDogcHVibGljIE15QmFzZTxUPiB7CnB1YmxpYzoKICBNeURlcml2ZWQoKTsKICB2aXJ0dWFsIH5NeURlcml2ZWQoKTsKICB2aXJ0dWFsIHZvaWQgZG9Tb21ldGhpbmcoKTsKfTsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpNeURlcml2ZWQ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