Есть такой код:
#include <iostream>
using namespace std;
class functor
{
int state;
public:
functor(int initial):state(initial) {}
void operator()() { ++state; printf("state %d\n", state); }
};
void do_for_each( int count, functor& action ) // line 13
{
while(--count >= 0)
action();
}
int main()
{
do_for_each( 3, functor(12) ); // line 21
return 0;
}
VC компилирует его и исполняет на ура.
GCC отказывается с такими матюками
C:\tests\temp_args\main.cpp||In function `int main()':|
C:\tests\temp_args\main.cpp|21|error: invalid initialization of non-const reference of type 'functor&' from a temporary of type 'functor'|
C:\tests\temp_args\main.cpp|14|error: in passing argument 2 of `void do_for_each(int, functor&)'|
Как этот GCC уговорить чтобы он понял что я ему хочу сказать?