I know this is a silly question, but is this code okay? It compiles on my compiler (not, of course, that that means anything):
(I know that structs are public by default etc.)Code:class aclass {};
int main(void) {
struct aclass a;
}
Printable View
I know this is a silly question, but is this code okay? It compiles on my compiler (not, of course, that that means anything):
(I know that structs are public by default etc.)Code:class aclass {};
int main(void) {
struct aclass a;
}
class and structs are the same thing, though in your example prefixing struct to your class instance wouldn't make its member public ( if it had any)
I don't think structs have inheritance.
- SirCrono6
Nope. That is incorrect.Quote:
Originally Posted by SirCrono6
Structs and classes will produce the exact same assembly code.
The 2 important differences are
- structs are public by default
- forward declarations must match (i.e. a forward declared class cannot be defined as a struct or vice versa)
Okay, thanks, I guess I didn't know point 2. :)
You probably want to use classes, they were designed for C++ whereas structs were left over from C. Good luck!
EDIT: I didnt mean to imply they were different, but i believe the standard is Classes
Actually, as mentioned, they're almost exactly the same thing. Read the thread.