3 ms·
So when using a class as a struct (all public member variables and unless I missed it, no function), it's better to use the keyword "struct" rather than "class"
by prof_hobart 13y ago
So when using a class as a struct (all public member variables and unless I missed it, no function), it's better to use the keyword "struct" rather than "class"? Say it ain't so...
- eropple 13y agoTo the best of my knowledge, you can use methods in a POD struct so long as it's not polymorphic. With no vtable, it'll be represented as a C struct would. It's not header-compatible with C, though.
- nicolasgz 13y agoThere are no rules to limit the kinds of member functions you can add to a struct. Structs can be polymorphic, can have vtables, and don't need to be compatible with C.
- eropple 13y agoYes, I know. As discussed elsewhere in this thread, there are cultural connotations to the term 'struct' that lead it to be used almost universally for POD, but--to ensure no ambiguity--that's why I said 'POD struct'.
- prof_hobart 13y agoYou can. But my point is that as soon as you're using a class as an actual class rather than a struct, you'll probably have both public and private elements and at that point, I'm not sure any of the "advantages" described in the article are still relevant.