Is there any difference between
class C {
static int func();
};
and
class C {
int static func();
};
I'm trying to remove the keyword static in someone else's code base. And I want to make sure I understand what the second example means before I do that.
[Edit] The reason to remove static: C was a "class" with no member variables and full of static methods. I think it's more proper to make "C" a namespace with normal functions instead of a class.
There is no difference. static
on the function declaration applies to the function.
An this
pointer will not be implicitly passed to this function, So you cannot access non static class members inside this function without explicitly passing the object to it.
To remove the static
first you should know and understand the purpose that it is designed this way. Without taking that in to consideration you are just bound to create a code smell of vast proportions.
Yes, in the first case, the keyword static
comes before the type int
, in the second, they are the other way around. However, like many things in C and C++, there is no semantic difference. So, other than "cosmetically", there is no difference.
I'm not sure why you would want to remove static
in classes as a general rule - there is probably a good reason a member function is declared static
.
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