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);
}
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);
}