In the example below, a function f
of Foo
tries to access the constant defined in the base class. Since the base class type my
is only defined in the header, it should not be visible in the function argument in cpp. This is correctly detected by MSVC but gcc still compiles it without problem. Which specialty of gcc that allows this?
foo.h
template<int TDegree>
class Base
{
public:
static const int dim = 3;
};
template<int TDim> class Vector {};
template<int TDegree>
class Foo : public Base<TDegree>
{
public:
typedef Base<TDegree> my;
void f(const Vector<my::dim>& v) const;
};
foo.cpp
#include "foo.h"
template<int TDegree>
void Foo<TDegree>::f(const Vector<my::dim>& v) const {}
// instantiation
template class Foo<1>;
The error message with MSVC is:
<source>(21): error C2244: 'Foo<TDegree>::f': unable to match function definition to an existing declaration
<source>(21): note: see declaration of 'Foo<TDegree>::f'
<source>(21): note: definition
<source>(21): note: 'void Foo<TDegree>::f(const Vector<Base<TDegree>::dim> &) const'
<source>(21): note: existing declarations
<source>(21): note: 'void Foo<TDegree>::f(const Vector<Base<TDegree>::dim> &) const'