R
riccardo.gherardi
Hello.
The code below results in a linker error when compiled with Visual
Studio 2008, v9.0.21022.8 RTM.
The problem disappears when Foo::Bar implementation is moved to the
header file.
I've read the relevant template FAQs suggesting to never separate
definition and declaration of template member functions, but they deal
with code that fails to compile.
It's a sintax issue (and therefore my fault) or a compiler quirk?
Thanks in advance, R
// --- foo.h ---
class Foo
{
public:
template<class T> int Bar(int);
};
// --- foo.cpp ---
#include "foo.h"
template<class T> int Foo::Bar(int)
{
return 0;
}
// --- main.cpp ---
#include "foo.h"
int main()
{
Foo f;
int x = f.Bar<double>(3);
}
The code below results in a linker error when compiled with Visual
Studio 2008, v9.0.21022.8 RTM.
The problem disappears when Foo::Bar implementation is moved to the
header file.
I've read the relevant template FAQs suggesting to never separate
definition and declaration of template member functions, but they deal
with code that fails to compile.
It's a sintax issue (and therefore my fault) or a compiler quirk?
Thanks in advance, R
// --- foo.h ---
class Foo
{
public:
template<class T> int Bar(int);
};
// --- foo.cpp ---
#include "foo.h"
template<class T> int Foo::Bar(int)
{
return 0;
}
// --- main.cpp ---
#include "foo.h"
int main()
{
Foo f;
int x = f.Bar<double>(3);
}