digitalmars.D.learn - getting type of object
- 0ffh (12/12) Nov 11 2007 Hi,
- 0ffh (2/2) Nov 11 2007 May I "if (theInstance.classinfo==TheClass.classinfo)"?
- Bill Baxter (4/8) Nov 11 2007 Does the comment about Typeinfo and Polymorphism help you at all?
- 0ffh (5/13) Nov 11 2007 I'll take that as a "yes"... =)
- Bill Baxter (4/19) Nov 11 2007 That sounds ok. If you want to see hackish uses of classinfo go visit
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: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, FrankMay 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
Nov 11 2007
0ffh wrote:Bill Baxter wrote:That sounds ok. If you want to see hackish uses of classinfo go visit the source code for std.boxer. --bb0ffh wrote: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, FrankMay 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
Nov 11 2007