typeof()

Steven Schveighoffer schveiguy at yahoo.com
Thu Oct 20 06:55:42 PDT 2011


On Thu, 20 Oct 2011 09:46:09 -0400, J Arrizza <cppgent0 at gmail.com> wrote:

> Maybe I'm doing something else incorrectly:
>
[snip]
>
> which still seems to support that typeof() doesn't return the underlying
> type.

typeid is not typeof.  Reread the response below.

However, note that typeid returns a TypeInfo object, which is used at  
runtime, not at compile time.  D's runtime type info is very limited, so  
you may not be able to get what you are looking for.

-Steve

>
> On Thu, Oct 20, 2011 at 12:25 AM, Jens Mueller  
> <jens.k.mueller at gmx.de>wrote:
>
>> J Arrizza wrote:
>> > typeof returns the type of the object given to it:
>> >
>> >     SomeClass sc;
>> >     typeof(sc)  // returns SomeClass
>> >
>> >     Object o = sc;
>> >     typeof(o) // returns Object
>> >
>> > Is there a way or call to get the underlying type?:
>> >
>> >     typeof2(o) //returns SomeClass
>> >
>> > I checked the online doc, but nothing in the Declarations section  
>> that I
>> > could see.
>>
>> typeid should work.
>> http://d-programming-language.org/expression.html#TypeidExpression
>>
>> Jens
>>
>
>


More information about the Digitalmars-d mailing list