My program can't be compiled through by GCC 4.3.3. The part of the program causing the problem is simplified as the following short code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <functional>
usingnamespace std;
class op : public unary_function<int,int> {
public:
intoperator()(int) {}
};
class test {
public:
void func(unary_function<int,int> & o = op()) {}
};
int main()
{
}
The compiler complained that the type of the default argument is not comply with the type of the parameter. I don't know why this happened. Please help me out. Thanks!
The problem is that the function parameter is a reference but the default value is a temporary.
I believe that you want a const reference void func ( const unary_function<int,int> & o = op() ) {}