I have a function which accepts an operator object as an argument. This operator is treated sort of like a callback. The type of this operator object is a template parameter. How can I specify a default parameter for it?
#include <iostream>
template<class IT, class NT>
class A
{
public:
class DefaultHandler
{
public:
NT foo() { return NT(); }
};
template <class HANDLER>
void action(HANDLER h = DefaultHandler()) // This default parameter is accepted by the compiler but appears to have no effect
{
std::cout << h.foo() << std::endl;
}
};
int main()
{
A<int, double> a;
// I want this to be legal:
a.action(); // error: no matching function for call to ‘A<int, double>::action()’
//a.action(A<int, double>::DefaultHandler()); // Works
return 0;
}