Out-of-line template function

J

Jaap

Hi,

I'm trying to get a member template of a template class defined
out-of-line. I'm failing miserably, though. Is this even possible ?

template <typename T>
struct foo
{
// Declare member template
template <typename U>
void bar(U);
};

// Define member template
template <typename T, typename U>
void foo<T>::bar(U)
{
}

VC.NET gives me:

ref.cpp(13) : error C2244: 'bar' : unable to match function definition
to an existing declaration
definition
'void foo<T>::bar(T2)'
existing declarations
'void foo<T>::bar(U)'

GCC says:

Line 10: error: prototype for `void foo::bar(U)' does
not match any in class `foo'
Line 5: error: candidate is: template
template void foo::bar(U)
Line 10: error: template definition of non-template `
void foo::bar(U)'


Any insights are appreciated,

Jaap
 
J

John Harrison

Jaap said:
Hi,

I'm trying to get a member template of a template class defined
out-of-line. I'm failing miserably, though. Is this even possible ?

template <typename T>
struct foo
{
// Declare member template
template <typename U>
void bar(U);
};

// Define member template
template <typename T, typename U>
void foo<T>::bar(U)
{
}

[snip]



Any insights are appreciated,

Jaap

template <typename T>
template <typename U>
void foo<T>::bar(U)
{
}

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top