{"id":12,"date":"2007-11-08T22:21:12","date_gmt":"2007-11-09T03:21:12","guid":{"rendered":"http:\/\/jaimerios.com\/?p=12"},"modified":"2007-11-08T22:21:12","modified_gmt":"2007-11-09T03:21:12","slug":"getting-the-datatype-of-an-object","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=12","title":{"rendered":"Getting the datatype of an object"},"content":{"rendered":"<p>In Java and C#, it&#8217;s really easy getting the datatype of an object that you are working with. If you don&#8217;t know what I am talking about, post a comment and I&#8217;ll explain it in more detail.Well anyway,\u00a0surprisingly,\u00a0I never had the need, until now, to do the same thing in C++. In other languages, you have the &#8220;typeof&#8221; keyword that allows you to get the datatype of an object.<\/p>\n<p>This keyword exists on the Mac, but doesn&#8217;t do the same thing. To get the same type of functionality, you can use the &#8220;typeid&#8221; class\u00a0to get the datatype and name of the object you are working on:<\/p>\n<p style=\"font: normal normal normal 10px\/normal Monaco; margin: 0px\"><span style=\"color: #760f50\">void<\/span> GetMyType()<\/p>\n<p style=\"font: normal normal normal 10px\/normal Monaco; margin: 0px\">{<\/p>\n<p style=\"font: normal normal normal 10px\/normal Monaco; margin: 0px\"><span class=\"Apple-tab-span\" style=\"white-space: pre\">\t<\/span><span style=\"color: #760f50\">int<\/span> i = <span style=\"color: #0000ff\">0<\/span>;<\/p>\n<p style=\"font: normal normal normal 10px\/normal Monaco; margin: 0px\"><span class=\"Apple-tab-span\" style=\"white-space: pre\">\t<\/span>cout &lt;&lt; <span style=\"color: #760f50\">typeid<\/span>(i).name();<\/p>\n<p><span class=\"Apple-style-span\" style=\"font-family: Monaco; font-size: 10px; line-height: normal\">}<\/span>\u00a0\u00a0<\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Java and C#, it&#8217;s really easy getting the datatype of an object that you are working with. If you don&#8217;t know what I am talking about, post a comment and I&#8217;ll explain it in more detail.Well anyway,\u00a0surprisingly,\u00a0I never had the need, until now, to do the same thing in C++. In other languages, you &#8230; <a title=\"Getting the datatype of an object\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=12\" aria-label=\"Read more about Getting the datatype of an object\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}