Re: Is there any way to define an interface that can implicitly convert to Object?

2019-07-10 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 10 July 2019 at 08:03:30 UTC, Nathan S. wrote:

I want to be able to do things like:

---
bool isSame(Object a, Object b) { return a is b; }

interface SomeInterface { int whatever(); }

bool failsToCompile(SomeInterface a, SomeInterface b) { return 
isSame(a, b); }

---

Error: function isSame(Object a, Object b) is not callable 
using argument types (SomeInterface, SomeInterface)


Is there a way to declare an interface as explicitly not a COM 
interface or a C++ interface? Having to add "cast(Object)" 
everywhere is annoying.


Hi, not tested extensively but :

---
interface Foo
{
final Object asObject()
{
return cast(Object) this;
}

alias asObject this;
}

class Bar : Foo
{

}

void main(string[] args)
{
Foo foo = new Bar;
Object o = foo;
writeln(o);
}
---


Is there any way to define an interface that can implicitly convert to Object?

2019-07-10 Thread Nathan S. via Digitalmars-d-learn

I want to be able to do things like:

---
bool isSame(Object a, Object b) { return a is b; }

interface SomeInterface { int whatever(); }

bool failsToCompile(SomeInterface a, SomeInterface b) { return 
isSame(a, b); }

---

Error: function isSame(Object a, Object b) is not callable using 
argument types (SomeInterface, SomeInterface)


Is there a way to declare an interface as explicitly not a COM 
interface or a C++ interface? Having to add "cast(Object)" 
everywhere is annoying.