tag:blogger.com,1999:blog-6042417775578107106.post1251022791571966002..comments2023-08-05T11:30:32.754-04:00Comments on The Hacks of Life: C++ Objects Part 4: typeid and castsChrishttp://www.blogger.com/profile/14648675681957285299noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6042417775578107106.post-55248972842894455202008-08-08T22:03:00.000-04:002008-08-08T22:03:00.000-04:00I've used this:R r;string rtype = typeid(r).name()...I've used this:<BR/>R r;<BR/>string rtype = typeid(r).name();<BR/><BR/>It's clunky, very slow, and gives unpredictable results for some non-builtin types, though. For testing type char, I use if (sizeof(r)) == 1; but again, clunky.shagbarkhttps://www.blogger.com/profile/07759080646499030919noreply@blogger.comtag:blogger.com,1999:blog-6042417775578107106.post-87969340954418024512008-08-07T17:35:00.000-04:002008-08-07T17:35:00.000-04:00shagbark:Have you tried"if(typeid(R) == typeid(cha...shagbark:<BR/><BR/>Have you tried<BR/>"if(typeid(R) == typeid(char))"?<BR/><BR/>This works for me between two classes, I'm not sure if it will work with built-in typesUnknownhttps://www.blogger.com/profile/10012205781361857975noreply@blogger.comtag:blogger.com,1999:blog-6042417775578107106.post-18386421442842801702008-07-23T12:37:00.000-04:002008-07-23T12:37:00.000-04:00How do you compare the result of typeid to a known...How do you compare the result of typeid to a known class?<BR/><BR/>if (typeid(R) == char)<BR/><BR/>doesn't work.shagbarkhttps://www.blogger.com/profile/07759080646499030919noreply@blogger.com