Suppose I have:
Foo foo;
is there a shorthand for this?
foo.operator->().operator()(1, 2);
Suppose I have:
Foo foo;
is there a shorthand for this?
foo.operator->().operator()(1, 2);
Well... Yes. The shorter form would look as
foo.operator->()(1, 2)
As for eliminating the operator ->
part... From the information you supplied so far it is impossible to say, but if it is implemented the way I can guess it is implemented (judging from your expression), then you can't eliminate it.
In C++ the use of overloaded ->
operator in an expression is interpreted as a chain of repetitive overloaded ->
calls, which eventually ends in a built-in ->
invocation. This means that at some point the overloaded ->
must return a pointer. Your overloaded ->
obviously doesn't return a pointer. So, in order to use it you have no other choice but to spell it out explicitly as operator ->()
.
Assuming you actually meant foo.operator->().operator()(1, 2)
, and that you have control over the class Foo
, a simpler form would be (*foo)(1, 2)
. It requires the operator*
to that defined though, but since we usually expect foo->bar
to be equivalent to (*foo).bar
, it seems reasonable.
If your Foo
is a smart pointer class of some sort, which points to an object which defines an operator()
, this would be the most concise way of calling the object's operator()
.
But without more detail (and without you providing an expression that's actually valid C++ -- there's no way in which operator(1, 2)
as you wrote it can be valid), it's impossible to answer your question. I'm just guessing at what you're trying to do.
Well, no, but, assuming you have write permissions to the class, you could define another member function that calls operator(), and then you'd have something like:
foo->myfunc(1,2);
That you find yourself in this position is a sign that you (or the person who wrote this class) is being a bit too cute with operator overloading.