{"action":"created","issue":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/251","labels_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/251/labels{/name}","comments_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/251/comments","events_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/251/events","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/251","id":109378901,"number":251,"title":"Implementation of alternative to dynamic_cast way of identifying types","user":{"login":"mcvsama","id":110877,"avatar_url":"https://avatars.githubusercontent.com/u/110877?v=3","gravatar_id":"","url":"https://api.github.com/users/mcvsama","html_url":"https://github.com/mcvsama","followers_url":"https://api.github.com/users/mcvsama/followers","following_url":"https://api.github.com/users/mcvsama/following{/other_user}","gists_url":"https://api.github.com/users/mcvsama/gists{/gist_id}","starred_url":"https://api.github.com/users/mcvsama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcvsama/subscriptions","organizations_url":"https://api.github.com/users/mcvsama/orgs","repos_url":"https://api.github.com/users/mcvsama/repos","events_url":"https://api.github.com/users/mcvsama/events{/privacy}","received_events_url":"https://api.github.com/users/mcvsama/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/labels/resolved","name":"resolved","color":"009800"}],"state":"closed","locked":false,"assignee":{"login":"BjarneStroustrup","id":10933044,"avatar_url":"https://avatars.githubusercontent.com/u/10933044?v=3","gravatar_id":"","url":"https://api.github.com/users/BjarneStroustrup","html_url":"https://github.com/BjarneStroustrup","followers_url":"https://api.github.com/users/BjarneStroustrup/followers","following_url":"https://api.github.com/users/BjarneStroustrup/following{/other_user}","gists_url":"https://api.github.com/users/BjarneStroustrup/gists{/gist_id}","starred_url":"https://api.github.com/users/BjarneStroustrup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BjarneStroustrup/subscriptions","organizations_url":"https://api.github.com/users/BjarneStroustrup/orgs","repos_url":"https://api.github.com/users/BjarneStroustrup/repos","events_url":"https://api.github.com/users/BjarneStroustrup/events{/privacy}","received_events_url":"https://api.github.com/users/BjarneStroustrup/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-10-01T20:39:52Z","updated_at":"2015-10-09T19:26:54Z","closed_at":"2015-10-09T19:26:54Z","body":"Some libraries make their own `int type()` methods for identification of types, to avoid using dynamic_cast. Every subclass is supposed to return a different integer. It's easy, but it might be harder to maintain if user is allowed to add his own subclasses.\r\n\r\nMy idea is to use `const char* type()` that points to publicly visible static member of the class, which can be a name of a class for example (with namespaces and stuff, so it's unique).\r\n\r\nPros:\r\n* still as fast as an int\r\n* better to debug (if the string is meaningful).\r\n* no need for extending some common enum where all such types are listed, the ID is contained in the class itself (a static public data member).\r\n\r\nCons:\r\n* can't use in a switch() without casting."},"comment":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/comments/146966995","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/251#issuecomment-146966995","issue_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/251","id":146966995,"user":{"login":"BjarneStroustrup","id":10933044,"avatar_url":"https://avatars.githubusercontent.com/u/10933044?v=3","gravatar_id":"","url":"https://api.github.com/users/BjarneStroustrup","html_url":"https://github.com/BjarneStroustrup","followers_url":"https://api.github.com/users/BjarneStroustrup/followers","following_url":"https://api.github.com/users/BjarneStroustrup/following{/other_user}","gists_url":"https://api.github.com/users/BjarneStroustrup/gists{/gist_id}","starred_url":"https://api.github.com/users/BjarneStroustrup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BjarneStroustrup/subscriptions","organizations_url":"https://api.github.com/users/BjarneStroustrup/orgs","repos_url":"https://api.github.com/users/BjarneStroustrup/repos","events_url":"https://api.github.com/users/BjarneStroustrup/events{/privacy}","received_events_url":"https://api.github.com/users/BjarneStroustrup/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T19:26:54Z","updated_at":"2015-10-09T19:26:54Z","body":"See C.146. There is a huge variety of ways of \"Faking RTTI\" and they are all less than general and somewhat error-prone."}}