Hi adam, the difference is, in the video, that guy's main function declares a
temporary X object. It doesn't have a name.
X(8)("Hi");
first constructs a temporary object with X(8), and then calls its () operator.
But you're making a named, non-temporary object, named f, so you can't apply the same syntax.
If you don't want to make a temporary variable, you have to split it into two calls.
Options A:
1 2
|
Functor f(4);
f("hey");
|
Option B:
______________________________
Edit in response to edit:
,how the above line is not creating an instance of a Functor so how can we use it in this way? |
Functor(4);
does create an instance of a Functor. But it's a temporary (unnamed) instance of it.
It's just like if you were to do something like this:
1 2 3 4 5 6
|
class Foo { };
int main()
{
Foo foo = Foo(); // the "Foo()" is a temporary object.
}
|