J
jrwats
I'm trying to write a templated function within a templated class, but
keep getting:
Test.h:31: error: no matching function for call to
‘List<int>::Map(List<T>::blah() [with T = int]::Functor)’
Test.h:45: error: no matching function for call to ‘List<int>::Map()’
With the following code:
template <class T>
class List
{
public:
// Function template
template <class Functor>
int Map(const Functor& func);
// Returns NULL if not found.
int blah();
int blah2();
};
template <class T>
template <class Functor>
int List<T>::Map(const Functor& func)
{
return func() ? 0 : 1;
}
template<class T>
int List<T>::blah()
{
class Functor
{
bool operator()()
{
return true;
}
};
return Map(Functor());
}
template<class T>
int List<T>::blah2()
{
class Functor
{
bool operator()()
{
return true;
}
};
return Map<Functor>();
}
void blah()
{
List<int> list;
list.blah();
list.blah2();
}
keep getting:
Test.h:31: error: no matching function for call to
‘List<int>::Map(List<T>::blah() [with T = int]::Functor)’
Test.h:45: error: no matching function for call to ‘List<int>::Map()’
With the following code:
template <class T>
class List
{
public:
// Function template
template <class Functor>
int Map(const Functor& func);
// Returns NULL if not found.
int blah();
int blah2();
};
template <class T>
template <class Functor>
int List<T>::Map(const Functor& func)
{
return func() ? 0 : 1;
}
template<class T>
int List<T>::blah()
{
class Functor
{
bool operator()()
{
return true;
}
};
return Map(Functor());
}
template<class T>
int List<T>::blah2()
{
class Functor
{
bool operator()()
{
return true;
}
};
return Map<Functor>();
}
void blah()
{
List<int> list;
list.blah();
list.blah2();
}