{"action":"created","issue":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/186","labels_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/186/comments","events_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/186/events","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/186","id":108630429,"number":186,"title":"struct and class ambiguity","user":{"login":"mambu","id":210711,"avatar_url":"https://avatars.githubusercontent.com/u/210711?v=3","gravatar_id":"","url":"https://api.github.com/users/mambu","html_url":"https://github.com/mambu","followers_url":"https://api.github.com/users/mambu/followers","following_url":"https://api.github.com/users/mambu/following{/other_user}","gists_url":"https://api.github.com/users/mambu/gists{/gist_id}","starred_url":"https://api.github.com/users/mambu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mambu/subscriptions","organizations_url":"https://api.github.com/users/mambu/orgs","repos_url":"https://api.github.com/users/mambu/repos","events_url":"https://api.github.com/users/mambu/events{/privacy}","received_events_url":"https://api.github.com/users/mambu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-28T10:35:06Z","updated_at":"2015-10-12T12:27:00Z","closed_at":"2015-10-12T12:27:00Z","body":"Hello,\r\n\r\nI would like to raise a discussion on two keywords that can be used for the same purpose but with one exception: struct and class.\r\nAlso refer to section C.2 of the guidelines \"Use class if the class has an invariant; use struct if the data members can vary independently\" which touches on the using struct and class for different purposes (and avoid overlapping).\r\n\r\nWhat I have always found annoying and confusing is that we can have two words to do the same thing with one exception: struct must be used if you want to define a \"C\" POD. Therefore my suggestion is to assign clear meanings to the two keywords:\r\n  * struct: \"C\" POD only (that allows the compiler to do validations)\r\n  * class: the same meaning it has now\r\n\r\nAlso I believe it is a good practice to always mark sections inside a class with their access specifier (public, protected or private) anyway so there should not be any savings on typing when using struct.\r\n\r\nBenefits:\r\n  * clear purpose of every keyword\r\n  * no overlapping between the two\r\n  * compiler can verify compatibility with \"C\" POD when using struct\r\n    * software can evolve and change, but something that you created as a POD will never lose this property (for instance adding a virtual method, which is something that can be done in C++)\r\n    * better interoperability with C libraries\r\n  * other OOP languages have one keyword only (and probably that is \"class\")\r\n\r\nAny thoughts?\r\n\r\nMarco"},"comment":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/comments/147381425","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/186#issuecomment-147381425","issue_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/186","id":147381425,"user":{"login":"gdr-at-ms","id":11031650,"avatar_url":"https://avatars.githubusercontent.com/u/11031650?v=3","gravatar_id":"","url":"https://api.github.com/users/gdr-at-ms","html_url":"https://github.com/gdr-at-ms","followers_url":"https://api.github.com/users/gdr-at-ms/followers","following_url":"https://api.github.com/users/gdr-at-ms/following{/other_user}","gists_url":"https://api.github.com/users/gdr-at-ms/gists{/gist_id}","starred_url":"https://api.github.com/users/gdr-at-ms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdr-at-ms/subscriptions","organizations_url":"https://api.github.com/users/gdr-at-ms/orgs","repos_url":"https://api.github.com/users/gdr-at-ms/repos","events_url":"https://api.github.com/users/gdr-at-ms/events{/privacy}","received_events_url":"https://api.github.com/users/gdr-at-ms/received_events","type":"User","site_admin":false},"created_at":"2015-10-12T12:27:00Z","updated_at":"2015-10-12T12:27:00Z","body":"There is little actionable items that can be added to the existing guidelines on this specific issue."}}