Here's an example class with a static function: - C++ Class

C++ examples for Class:static member

Description

Here's an example class with a static function:

Demo Code

#include <iostream>
#include <string>

using namespace std;

class Util/* w w w.ja  v  a2s .  c o  m*/
{
public:
    static string MyClassName() {
        return "Util!";
    }
    int WhichUtil;
    int Chew(string name) {
        cout << WhichUtil << endl;
        cout << name << endl;
        return WhichUtil;
    }
};

int main()
{
    typedef string (*StaticMember)();
    StaticMember staticfunc = &Util::MyClassName;
    cout << staticfunc() << endl;
}

Result


Related Tutorials