Reputation: 143
im trying to perform operator overloading on a temporary object like in this example:
class changeStrToInt
{
public:
int operator()(std::string x) {
return 10;
}
};
int main()
{
changeStrToInt obj; //works
int i = obj("lala");
int x = changeStrToInt("lala"); // doesnt work
}
So my question is how can i make int x = changeStrToInt("lala"); work?
Upvotes: 0
Views: 306
Reputation: 217583
changeStrToInt("lala")
tries to call constructor of changeStrToInt
with "lala"
.
You want:
changeStrToInt()("lala")
changeStrToInt{}("lala")
Upvotes: 1