pointer to object resolution
Alex
sascha.orlov at gmail.com
Fri May 11 12:53:25 UTC 2018
Hi all,
I'm sure, I didn't find something obvious, but:
Given this:
´´´
void main()
{
auto s = S();
s.operator;
assert(s.myOp(42));
assert(42 in s);
auto sptr = new S();
sptr.operator;
assert(sptr.myOp(42));
//assert(42 in sptr); //<-- does not compile
}
struct S
{
void operator() const
{
assert(true);
}
bool opBinaryRight(string op)(size_t input) const if(op == "in")
{
return true;
}
bool myOp(size_t input)
{
return input in this;
}
}
´´´
The last line in the main does not compile with the message
source/app.d(9,9): Error: incompatible types for `(42) in
(sptr)`: `int` and `S*`
This behaves differently, w.r.t. to an arbitrary method, like
"operator". Why? Is there any workaround?
More information about the Digitalmars-d-learn
mailing list