digitalmars.D - Using typedefed types as covariant return types
- Rick Mann (17/17) Feb 07 2007 I didn't get any responses in D.learn for this question, so I decided ma...
- Bill Baxter (10/32) Feb 07 2007 That's not the message I get from reading the docs. What I see:
- Stewart Gordon (17/36) Feb 08 2007 Are you taking this to mean distinct from each other or distinct from th...
-
Rick Mann
(3/5)
Feb 11 2007
It seems to be implied by the "Implicit Conversions" section of
- Bruno Medeiros (7/15) Feb 12 2007 Implicitly convertible doesn't mean a type is a subtype of another.
- Frits van Bommel (3/11) Feb 12 2007 Perhaps he meant the "to its base type" part? I could see someone mixing...
- Bruno Medeiros (5/17) Feb 12 2007 True enough, that may cause some confusion.
- Rick Mann (2/14) Feb 17 2007 In that case, I'd like to make it a feature request. It seems only natur...
I didn't get any responses in D.learn for this question, so I decided maybe it was advanced enough for this group. I was hoping I could do this: typedef void* CFTypeRef; typedef CFTypeRef CFStringRef; class DCFObject { CFTypeRef getRef() {} } class DString : DCFObject { CFStringRef getRef() {} } But the compiler gives me: src/d/darbon/corefoundation/DString.d:32: function darbon.corefoundation.DString.DString.getRef of type CFStringRef() overrides but is not covariant with darbon.corefoundation.DCFObject.DCFObject.getRef of type CFTypeRef() From what I gather in the docs, CFStringRef is derived from CFTypeRef, so this should be acceptable. Am I missing something? TIA, Rick
Feb 07 2007
Rick Mann wrote:I didn't get any responses in D.learn for this question, so I decided maybe it was advanced enough for this group. I was hoping I could do this: typedef void* CFTypeRef; typedef CFTypeRef CFStringRef; class DCFObject { CFTypeRef getRef() {} } class DString : DCFObject { CFStringRef getRef() {} } But the compiler gives me: src/d/darbon/corefoundation/DString.d:32: function darbon.corefoundation.DString.DString.getRef of type CFStringRef() overrides but is not covariant with darbon.corefoundation.DCFObject.DCFObject.getRef of type CFTypeRef() From what I gather in the docs, CFStringRef is derived from CFTypeRef, so this should be acceptable. Am I missing something?That's not the message I get from reading the docs. What I see: "Strong types are semantically a distinct type to the type checking system, for function overloading, and for the debugger." (http://www.digitalmars.com/d/declaration.html) Basically CFStringRef becomes something completely new and different from CTypeRef as far as the compiler is concerned. What are you reading that makes you think CFStringRef is "derived" from CFTypeRef? --bb
Feb 07 2007
Bill Baxter Wrote:Rick Mann wrote:<snip>I didn't get any responses in D.learn for this question, so I decided maybe it was advanced enough for this group. I was hoping I could do this: typedef void* CFTypeRef; typedef CFTypeRef CFStringRef;Are you taking this to mean distinct from each other or distinct from their underlying types? If the latter, this is much the same a class being different from its base class.From what I gather in the docs, CFStringRef is derived from CFTypeRef, so this should be acceptable. Am I missing something?That's not the message I get from reading the docs. What I see: "Strong types are semantically a distinct type to the type checking system, for function overloading, and for the debugger." (http://www.digitalmars.com/d/declaration.html)Basically CFStringRef becomes something completely new and different from CTypeRef as far as the compiler is concerned.What are you reading that makes you think it's _completely_ different? This compiles: ---------- typedef void* CFTypeRef; typedef CFTypeRef CFStringRef; void func(CFTypeRef p) {} void main() { CFStringRef s; func(s); } ----------What are you reading that makes you think CFStringRef is "derived" from CFTypeRef?Probably that typedefs implicitly convert to their underlying types. Moreover, typedefs behave in a number of respects very similarly to enums, for which the notation enum Enum : int suggests type derivation as with classes. Stewart.
Feb 08 2007
Bill Baxter Wrote:What are you reading that makes you think CFStringRef is "derived" from CFTypeRef?It seems to be implied by the "Implicit Conversions" section of <http://www.digitalmars.com/d/type.html>: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion. "
Feb 11 2007
Rick Mann wrote:Bill Baxter Wrote:Implicitly convertible doesn't mean a type is a subtype of another. Altough in this case of typedef and enums I think they could be subtypes of the base type. -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DWhat are you reading that makes you think CFStringRef is "derived" from CFTypeRef?It seems to be implied by the "Implicit Conversions" section of <http://www.digitalmars.com/d/type.html>: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion. "
Feb 12 2007
Bruno Medeiros wrote:Rick Mann wrote:Perhaps he meant the "to its base type" part? I could see someone mixing that up with the same term used in class hierarchies...Bill Baxter Wrote: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion. "Implicitly convertible doesn't mean a type is a subtype of another. Altough in this case of typedef and enums I think they could be subtypes of the base type.
Feb 12 2007
Frits van Bommel wrote:Bruno Medeiros wrote:True enough, that may cause some confusion. -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DRick Mann wrote:Perhaps he meant the "to its base type" part? I could see someone mixing that up with the same term used in class hierarchies...Bill Baxter Wrote: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion. "Implicitly convertible doesn't mean a type is a subtype of another. Altough in this case of typedef and enums I think they could be subtypes of the base type.
Feb 12 2007
Frits van Bommel Wrote:Bruno Medeiros wrote:In that case, I'd like to make it a feature request. It seems only natural to be able to use typedefs in this manner. Should I file a formal request via bug?Rick Mann wrote:Perhaps he meant the "to its base type" part? I could see someone mixing that up with the same term used in class hierarchies...Bill Baxter Wrote: "A typedef or enum can be implicitly converted to its base type, but going the other way requires an explicit conversion. "Implicitly convertible doesn't mean a type is a subtype of another. Altough in this case of typedef and enums I think they could be subtypes of the base type.
Feb 17 2007