www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why this compiles?

reply Antonio <antoniocabreraperez gmail.com> writes:
In this example,  ```a``` and ```b``` vars are not of the same 
type and don't implement the same interface.  **why 
```assert(a==b)``` compiles?**


```d
interface IOpt(T) {
   bool opEquals(const IOpt!T) const  safe pure;
}

class None(T) : IOpt!T {
   bool opEquals(const IOpt!T other) const  safe pure => true;
}

void main() {
   auto a = new None!int();
   auto b = new None!string();

   assert(a==b);
}
```
Nov 26 2023
parent Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 26 November 2023 at 21:45:21 UTC, Antonio wrote:
 In this example,  ```a``` and ```b``` vars are not of the same 
 type and don't implement the same interface.  **why 
 ```assert(a==b)``` compiles?**
They're both subclasses of Object and inherit a generic opEquals from that base.
Nov 26 2023