I am trying to use a local class as a functor and get compiler error using g++ (3.4.6).
Placing the below class ( Processor
) in the global scope resolves the error, so I guess the error is because of function local structures/classes. I would prefer to have the classes inside the function for code clarity and ease of use. Want to know if there is a workaround solution to make the below code working.
test.cpp:24: error: no matching function for call to \u2018foreachArg(int&, char*&, processSubs(int, char*)::Processor&)\u2019
template <class Functor>
void foreachArg(int n, char *args[], Functor& f)
{
for(int i=0; i<n; ++i)
f(args[i]);
}
int processSubs(int argc, char *args[])
{
class Processor
{
public:
void operator()(const char *arg)
{
}
};
Processor p;
foreachArg(argc, args, p);
}
int main(int argc, char *argv[])
{
processSubs(argc, argv);
}