Template function within class template not not resolving when passedfunction local class?

J

jrwats

I get the following error when I try passing a local (to the function)
class into the template function (Map) of the template class List.
It works with external functor classes defined outside the function
scope and Functors defined within the class template. Is there any
way to make this work for the local classes?

g++ -Wall Test.h -o Test
Test.h: In member function ‘int List<T>::blah3() [with T = int]’:
Test.h:89: instantiated from here
Test.h:65: error: no matching function for call to ‘List<int>::Map()’
Test.h: In function ‘int globalBlah(List<T>&) [with T = int]’:
Test.h:90: instantiated from here
Test.h:81: error: no matching function for call to
‘List<int>::Map(globalBlah(List<T>&) [with T = int]::Functor4&)’

template <class T> // line 1
class List
{
class Functor2;
public:
// Function template
template <class FunctorT>
int Map(const FunctorT& func = FunctorT());

// Returns NULL if not found.
int blah();
int blah2();
int blah3();
};

template <class T>
template <class Functor>
int List<T>::Map(const Functor& func)
{
return func() ? 0 : 1;
}

class Functor1
{
public:
bool operator()() const
{
return true;
}
};

template<class T>
class List<T>::Functor2
{
public:
bool operator()() const
{
return true;
}
};

template<class T>
int List<T>::blah()
{
return Map(Functor1());
}

template<class T>
int List<T>::blah2()
{
return Map<Functor2>();
}

template<class T>
int List<T>::blah3()
{
class Functor3
{
public:
bool operator()() const
{
return false;
}
};
return Map<Functor3>();
}

// Global template function
template<class T>
int globalBlah(List<T>& list)
{
class Functor4
{
public:
bool operator()() const
{
return false;
}
};
Functor4 f;
return list.Map(f);
}

void blah()
{
List<int> list;
list.blah();
list.blah2();
list.blah3();
globalBlah(list);
}
 
A

Anthony Williams

jrwats said:
I get the following error when I try passing a local (to the function)
class into the template function (Map) of the template class List.
It works with external functor classes defined outside the function
scope and Functors defined within the class template. Is there any
way to make this work for the local classes?

Not in current releases of gcc.

This is a C++0x feature not currently available in gcc. Some compilers
(e.g. MSVC) do support it, but gcc doesn't with the current stable
releases.

The gcc C++0x status page http://gcc.gnu.org/projects/cxx0x.html says
that it is supported in the upcoming gcc 4.5 release.

Anthony
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top