VC8 template base class member function visibility bug

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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();
}

.



Relevant Pages

  • Re: Non-inline template specialization of member function okay?
    ... template T Createconst; ... implemented in its CPP file: ... Member function specialization cannot be declared inside the class. ... INTERNAL COMPILER ERROR (compiler file ...
    (microsoft.public.vc.language)
  • Re: Non-inline template specialization of member function okay?
    ... Alex Blekhman wrote: ... definition of specialized member function in other translation ... if a definition of specialized template is ... templateclass Wrapper ...
    (microsoft.public.vc.language)
  • Re: Read a textfile to an array
    ... I need some help with writing a member function really badly. ... > template class with the constructor as follows: ... as a variable that's local to the ctor, so as soon as the ctor ... > was created by the constructor. ...
    (microsoft.public.vc.language)
  • Re: Read a textfile to an array
    ... I need some help with writing a member function really badly. ... >template class with the constructor as follows: ... Are the contents of the file supposed to be stored into the array you ...
    (microsoft.public.vc.language)
  • Re: What is wrong? (copy constr)
    ... >> qualified instance. ... Any member function has full access to all members of the ... the template type parameters for those items you want to template. ... If you want comment on some code you've placed on your web site, ...
    (alt.comp.lang.learn.c-cpp)