www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - interfaces and such

reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
--bcaec554d842465f9d04c5d0e9b4
Content-Type: text/plain; charset=UTF-8

I have a small question: why aren't interfaces implicitly convertible to
Object?

-- 
Bye,
Gor Gyolchanyan.

--bcaec554d842465f9d04c5d0e9b4
Content-Type: text/html; charset=UTF-8

I have a small question: why aren&#39;t interfaces implicitly convertible to
Object?<br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>

--bcaec554d842465f9d04c5d0e9b4--
Jul 27 2012
next sibling parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 27-07-2012 16:56, Gor Gyolchanyan wrote:
 I have a small question: why aren't interfaces implicitly convertible to
 Object?

 --
 Bye,
 Gor Gyolchanyan.

I don't know if there's any particular reason, but for what it's worth: Casting an interface to Object means going through its vtable back to the original object location. In other words, it's not "free" (though the cost is extremely minimal). -- Alex Rønne Petersen alex lycus.org http://lycus.org
Jul 27 2012
prev sibling next sibling parent "David Nadlinger" <see klickverbot.at> writes:
On Friday, 27 July 2012 at 14:56:18 UTC, Gor Gyolchanyan wrote:
 I have a small question: why aren't interfaces implicitly 
 convertible to
 Object?

Not all interfaces »originate« from D objects, they can also be COM interfaces. Using (cast(Object)foo) should work if foo is really an Object. David
Jul 27 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 27 Jul 2012 12:48:59 -0400, David Nadlinger <see klickverbot.at>=

wrote:

 On Friday, 27 July 2012 at 14:56:18 UTC, Gor Gyolchanyan wrote:
 I have a small question: why aren't interfaces implicitly convertible=


 Object?

Not all interfaces =C2=BBoriginate=C2=AB from D objects, they can also=

 interfaces. Using (cast(Object)foo) should work if foo is really an  =

 Object.

All Com interfaces inherit from IUnknown. This is statically known. The idea that we cannot tell which interfaces are COM and which are norm= al is a myth. There is no reason why interfaces (that aren't COM) shouldn't be implicitly castable to Object. -Steve
Aug 24 2012
prev sibling next sibling parent "Chris Nicholson-Sauls" <ibisbasenji gmail.com> writes:
On Friday, 24 August 2012 at 14:15:28 UTC, Steven Schveighoffer 
wrote:
 On Fri, 27 Jul 2012 12:48:59 -0400, David Nadlinger 
 <see klickverbot.at>
 wrote:

 On Friday, 27 July 2012 at 14:56:18 UTC, Gor Gyolchanyan wrote:
 I have a small question: why aren't interfaces implicitly 
 convertible to
 Object?

Not all interfaces »originate« from D objects, they can also be COM interfaces. Using (cast(Object)foo) should work if foo is really an Object.

All Com interfaces inherit from IUnknown. This is statically known. The idea that we cannot tell which interfaces are COM and which are normal is a myth. There is no reason why interfaces (that aren't COM) shouldn't be implicitly castable to Object. -Steve

Technically true, however COM is not the only example of foreign objects used via interfaces. The (limited) C++ compatibility, for example, works this way.
Aug 24 2012
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 24 Aug 2012 22:01:51 -0400, Chris Nicholson-Sauls  =

<ibisbasenji gmail.com> wrote:

 On Friday, 24 August 2012 at 14:15:28 UTC, Steven Schveighoffer wrote:=

 On Fri, 27 Jul 2012 12:48:59 -0400, David Nadlinger <see klickverbot.=


 wrote:

 On Friday, 27 July 2012 at 14:56:18 UTC, Gor Gyolchanyan wrote:
 I have a small question: why aren't interfaces implicitly convertib=




 to
 Object?

Not all interfaces =C2=BBoriginate=C2=AB from D objects, they can al=



 interfaces. Using (cast(Object)foo) should work if foo is really an =



 Object.

All Com interfaces inherit from IUnknown. This is statically known. The idea that we cannot tell which interfaces are COM and which are =


 normal
 is a myth.

 There is no reason why interfaces (that aren't COM) shouldn't be
 implicitly castable to Object.

 -Steve

Technically true, however COM is not the only example of foreign objec=

 used via interfaces.  The (limited) C++ compatibility, for example,  =

 works this way.

Those are extern(C++), also statically known. In fact, the very nature of how interfaces work makes it very difficult = = for us to *not* statically know that an interface is a D interface -- D'= s = implementation of interfaces is not like any others. -Steve
Aug 27 2012