digitalmars.D.learn - getting type of object
- 0ffh <spam frankhirsch.net> Nov 11 2007
- 0ffh <spam frankhirsch.net> Nov 11 2007
- Bill Baxter <dnewsgroup billbaxter.com> Nov 11 2007
- 0ffh <frank frankhirsch.youknow.what.todo.net> Nov 11 2007
- Bill Baxter <dnewsgroup billbaxter.com> Nov 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
Nov 11 2007
May I "if (theInstance.classinfo==TheClass.classinfo)"? Seems to work...
Nov 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
Nov 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
Nov 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
Nov 11 2007








Bill Baxter <dnewsgroup billbaxter.com>