In java we can make a method of a class to be static
by writing the keyword static
before the type of the method : public static string some_method() { ... }
In C++ how to make a method static
?
In java we can make a method of a class to be static
by writing the keyword static
before the type of the method : public static string some_method() { ... }
In C++ how to make a method static
?
You use the keyword static
just like in Java.
With your example:
public static string some_method() { ... }
In C++:
public:
static string some_method() { ... }
In this case, the colon (:
) is the only difference; though in C++, public:
designates all following functions as public
, not only the one it is attached to.
However, please take notice that this answer just gives a fish, instead of teaching to fish. Depending on what you want to achieve, there are plenty alternatives in C++ to achieve something in a sane, idiomatic way.