Friday, September 28, 2012

code to illustrate static function

#include <iostream>
#include <string>
using namespace std;

class Cat
{
    public:
        static int Add(int a, int b)
        {
            return a+b;
        }
};

int main()
{
    cout << "\n" << Cat::Add(5,67) << endl;
    return 0;
}


OUTPUT:

In this example we don't have to create an object of class to access the static function.

No comments:

Post a Comment