2
Contributors
1
Reply
25
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
0
c++ has static functions just like the ones on C language, and it also has static class methods, which one do you mean?

Static Functions
Static functions are visible to only the *.cpp file in which it is defined. This is only really useful in programs that have two or more *.cpp files in the project. A static function in one *.cpp file can not be called from functions in other *.cpp files. Static functions are probably most useful in libraries and DLLs where you don't want application programs calling them.

Static Methods

A static class method is one in which there is one, and only one instance regardless of the number of instances of the class itself.  A static method can not access any of the instance variables of the class or call any of the instance class methods.  This means that if a class has two methods, foo() and bar(), and foo() is a static method and bar() is not, then foo() can not call bar(), but bar() can call foo().





class MyClass
{
public:
    static int foo() {return 0;}
    int bar() { return foo(); }
};

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.