Thread overview
getting type of object
Nov 11, 2007
0ffh
Nov 11, 2007
0ffh
Nov 11, 2007
Bill Baxter
Nov 11, 2007
0ffh
Nov 11, 2007
Bill Baxter
November 11, 2007
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, 2007
May I "if (theInstance.classinfo==TheClass.classinfo)"?

Seems to work...
November 11, 2007
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, 2007
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, 2007
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