Normally a function is declared static so you can access it without having an instance of the class. They are special in that they don't have a 'this' pointer, and they can only access static members of the class. For example, you would call that function like this:
Output::print(5);
Of course, without actually seeing the context around that code, I can't tell exactly why they felt the need for a static function in a class, but hopefully you should at least understand what it is and how it might be used.
// multiple inheritance
#include <iostream>
usingnamespace std;
class Polygon {
protected:
int width, height;
public:
Polygon (int a, int b) : width(a), height(b) {}
};
class Output {
public:
staticvoid print (int i);
};
void Output::print (int i) {
cout << i << '\n';
}
class Rectangle: public Polygon, public Output {
public:
Rectangle (int a, int b) : Polygon(a,b) {}
int area ()
{ return width*height; }
};
class Triangle: public Polygon, public Output {
public:
Triangle (int a, int b) : Polygon(a,b) {}
int area ()
{ return width*height/2; }
};
int main () {
Rectangle rect (4,5);
Triangle trgl (4,5);
rect.print (rect.area());
Triangle::print (trgl.area());
return 0;
}
In the context of what you are saying that would make sense after looking at the above code.
The code was presented to illustrate the nature of multiple inheritance from a class.
Am I correct in thinking that "static void print (int i);" was stated in class Output so the return values of rect and trgl could be returned via cout as a result of having inherited "static void print (int i);" from Output?