| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
| 
 | 
| November 11, 2007getting type of object | ||||
|---|---|---|---|---|
| 
 | ||||
| Hi, if I have an object of class Foo, or a subclass of Foo, like: Foo foo=someInstanceOfFooOrItsSubclasses(); Is there a more elegant method to get the type of the object than adding a member function to Foo and all its subclasses that does something like: TypeInfo getType() { return typeid(typeof(this)); } ? Regards, Frank | ||||
| November 11, 2007Re: getting type of object | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to 0ffh | May I "if (theInstance.classinfo==TheClass.classinfo)"? Seems to work... | |||
| November 11, 2007Re: getting type of object | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to 0ffh | 0ffh wrote: > > May I "if (theInstance.classinfo==TheClass.classinfo)"? > > Seems to work... Does the comment about Typeinfo and Polymorphism help you at all? http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos/Object --bb | |||
| November 11, 2007Re: getting type of object | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Bill Baxter | Bill Baxter wrote: > 0ffh wrote: >> >> May I "if (theInstance.classinfo==TheClass.classinfo)"? >> >> Seems to work... > > Does the comment about Typeinfo and Polymorphism help you at all? > http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos/Object I'll take that as a "yes"... =) I was mainly concerned here if using the classinfo member counts as a hackish OMGWhatHaveYouGoneAndDoneNow??? or if it's okay to. Thanks, Frank | |||
| November 11, 2007Re: getting type of object | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to 0ffh | 0ffh wrote:
> Bill Baxter wrote:
>> 0ffh wrote:
>>>
>>> May I "if (theInstance.classinfo==TheClass.classinfo)"?
>>>
>>> Seems to work...
>>
>> Does the comment about Typeinfo and Polymorphism help you at all?
>> http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos/Object
> 
> I'll take that as a "yes"... =)
> I was mainly concerned here if using the classinfo member counts
> as a hackish OMGWhatHaveYouGoneAndDoneNow??? or if it's okay to.
> 
> Thanks, Frank
That sounds ok.  If you want to see hackish uses of classinfo go visit the source code for std.boxer.
--bb
 | |||
Copyright © 1999-2021 by the D Language Foundation
  Permalink
Permalink Reply
Reply