member templated definitions out of class scope


G

George

Hi All,

With gcc (3 or 4) the member template definition out of class scope
below compiles fine. But with Sun's CC 5.9, it fails with:

"main.cpp", line 7: Error: Could not find a match for Foo<T,
Policy<struct>>::bar<Foo<T, Policy<struct>>::U>(U).

This seems like a bug to me, has anyone else encountered this? Is
there any workaround beside putting the definition inside the class
decl?

Thanks much.

$ CC -V
CC: Sun C++ 5.9 Linux_i386 Patch 124865-01 2007/07/30

//main.h
#include <iostream>
#include <string>

template <typename T, template <class> class Policy >
struct Foo : Policy<T>
{
template <typename U> void bar(U u);
};

template <typename T>
class double_creator
{
T m_data;
};

//main.cpp
#include "main.h"
using namespace std;

template <typename T, template <class> class Policy >
template <typename U>
void Foo<T, Policy>::bar(U u)
{
cout << "Hello world " << u.c_str() << sizeof(T) << endl;
}
 
Ad

Advertisements

V

Victor Bazarov

George said:
With gcc (3 or 4) the member template definition out of class scope
below compiles fine. But with Sun's CC 5.9, it fails with:

"main.cpp", line 7: Error: Could not find a match for Foo<T,
Policy<struct>>::bar<Foo<T, Policy<struct>>::U>(U).

This seems like a bug to me, has anyone else encountered this? Is
there any workaround beside putting the definition inside the class
decl?

Consider asking in the newsgroup for Sun's compiler (one with "solaris"
in the name, maybe). You seem to have an issue with that particular
compiler, which makes it OT here.
Thanks much.

$ CC -V
CC: Sun C++ 5.9 Linux_i386 Patch 124865-01 2007/07/30

//main.h
#include <iostream>
#include <string>

template <typename T, template <class> class Policy >
struct Foo : Policy<T>
{
template <typename U> void bar(U u);
};

template <typename T>
class double_creator
{
T m_data;
};

//main.cpp
#include "main.h"
using namespace std;

template <typename T, template <class> class Policy >
template <typename U>
void Foo<T, Policy>::bar(U u)
{
cout << "Hello world " << u.c_str() << sizeof(T) << endl;
}

Seems OK to me. Are you sure you're _using_ that function in the
same module (main.cpp), though? Because if you aren't the compiler
may not be able to link it correctly...

V
 

Top