Visibility of class in the function argument

Hoang-Giang Bui 0 Reputation points
2023-01-18T15:27:48.87+00:00

Hello

This code below does not compile with VC++, although it compiles fine with gcc

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 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'

The class signature is exactly identical in both header and cpp, so why this error emitted from the compiler?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,547 questions
{count} votes