VC8 template base class member function visibility bug
Situation: A class Test with multiple base classes, one of which is a
template instance BaseTemplate<unsigned>. Then it should be impossible
to access a member function of BaseTemplate<unsigned> from Test by
writing:
BaseTemplate::test(123);
Indeed, VC7.1 and Intel 9.1 compiler complain that the template
parameter for BaseTemplate is missing. VC8 compiles this anyhow and
the result is terribly wrong. The function call jumps into no man's
land and modifies some of the other base classes' data.
That was my weekend.
Greetings, Max
#include <iostream>
using namespace std;
template
<typename T>
class BaseTemplate
{
T t;
public:
BaseTemplate(): t(0)
{
}
protected:
void test(unsigned i)
{
t+=i;
}
};
struct A
{
unsigned a;
A():a(0){}
};
struct B
{
unsigned b;
B():b(0){}
};
class Test:
public A,
public BaseTemplate<unsigned>,
public B
{
public:
void showProb()
{
BaseTemplate<unsigned>::test(123); //ok
cout<<b<<endl;
BaseTemplate::test(123); //should not compile
cout<<b<<endl; //ouch
}
};
int main()
{
Test test;
test.showProb();
}