#include <iostream>
class myFunctorClass
{
public:
myFunctorClass(int x) : _x(x) {}
int oprator() (int y) {return _x + y;}
private:
int _x;
}
int main(void)
{
myFunctorClass addFive(5);
std::cout << addFive(6);
std::cin.get();
return 0;
}
This is example code from here:
http://www.cprogramming.com/tutorial/functors-function-objects-in-c++.html
But I got errors:
Error 5 error C2065: 'y' : undeclared identifier
and
Error 2 error C2628: 'myFunctorClass' followed by 'int' is illegal (did you forget a ';'?)
I don’t have gcc now. Is this supposed to be compile under gcc or linux environment?
How to change it work in Visual Studio?
Update:
Problem solved.
I mis-spell operator
I lost one semicolon.
Thank you.
There are at least two problems here — in C++, unlike C# / Java, etc., you need a semicolon after your class declaration. The other issue is that you have misspelled “operator.”