What is the meaning of a static method in C++?
As I understand it’s the same as in Java: there is no need to create an instance of the class in order to call the static method.
As I remember, in C we used static declaration for methods in order to make them private.
How do I make private methods in C++?
Let’s say I want to calculate some calculation with a helper function:
class A{
foo();
};
A::foo(){
int a=doSomCalculations();
}
How would I define doSomecalculations so it will be as if private helper method as in Java?
In C++, if you don’t explicitly state that something is
public, it will beprivateby default. So if you wantfoo()to bepublicin your class, you need to state it so.As a comment on your C
staticthing, I don’t know of anything saying thatstaticmakes anythingprivatein C. C has no notion ofprivateandpublic. In C you only havestructtypes, and these are allpublicby default.In C++
structhave all memberspublicby default. If you want aprivatemember in astruct, you have to explicitly state it, like so:OTOH, there is
staticin C which meansinternal linkage. Perhaps you were referring to it like this.