Hi. Please excuse this post. I searched functor in this group and
had around 1600 hits. The first page couldn't help me. Would someone
be so kind as to look at this code and tell me why it won't compile?
I'm using a mingW compiler.
******************************code**************** ****************************
#include <iostream>
using namespace std;
class mySquare
{
public:
int operator()(int x) const { return x * x; }
}
int main(){
cout<<mySquare(2)<<endl;
return 0;
}
************************************************** ******************************
******************************error
messages********************************
************************************************** ******************************
error C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:10
new types may not be defined in a return type
error C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:10
extraneous `int' ignored
error C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:10
`main' must return `int'
C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp
[Warning] In function `int main(...)':
error C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:11
no matching function for call to `mySquare::mySquare(int)'
note C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:5
candidates are: mySquare::mySquare()
note C:\unisa\MyFiles\Test_bin\test_functor_and_polymor phism.cpp:5
mySquare::mySquare(const mySquare&)
************************************************** ******************************