Is there any difference between these:
struct Class* CreateClass();
and:
Class* CreateClass();
It's just a factory function declaration. You can see that one has struct at the start and one doesn't. I've tried it both ways and it doesn't seem to make a difference.
Which should I be using?
It's from C; there's no difference* in C++.
*Okay, I lied, sorry. :P You can confuse yourself if you really want to, and make them be different if you use a typedef
with the same name but a different underlying type, but normally they're not different. That's assuming Class
is already declared, though... if Class
is undeclared, the second one won't even compile.
That said, the convention is to do:
typedef struct Class { ... } Class;
so that it compiles the same way in both C and C++.
It doesn't make a difference as long as there's no function in scope with the same name Class
. You shouldn't write a function with the same name as a class, and to follow common C++ style you should use just Class *
.
[Edit: same correction as Mehrdad, no function or typedef]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With