Topic: Template & inheritance: GURUS please help
Author: rharmsen@knoware.nl (Ruud Harmsen)
Date: Tue, 21 Feb 1995 01:55:34 GMT Raw View
The following causes a syntax error under Borland C++ 3.1, and I just don't
understand why:
(see comments marked with @@@@@. The first compiler message, even if it were
justified, still is an outright lie, I think. A compiler bug, or my ignorance?
I hope the latter.
============================================================================
#include <stdio.h>
class B;
template <class someB> class A
{
public:
someB *aB;
};
class B
{
public:
virtual int BMethod(int arg);
void InternMethod(void);
};
int B::BMethod(int arg)
{
printf("In BMethod, arg=%d\n", arg);
return arg;
}
void B::InternMethod(void)
{
BMethod(13);
}
class myB: public B
{
public:
int BMethod(int arg);
};
class myA: public A<class MyB>
{
};
int main (int argc, char **argv)
{
class myA *aPA = new myA;
// @@@@@
// Here BorlandC++ 3.1 says:
// "InternMethod is not a member of MyB".
// WHY NOT? It is, isn't it?
aPA->aB->InternMethod();
delete aPA;
class myB *adB = new myB;
adB->InternMethod(); // @@@@@ but this is accepted !
return 0;
}
int myB::BMethod(int arg)
{
printf("In myB:BMethod, arg=%d\n", 2 * arg);
return arg;
}