Static method
You need to put the method inside the Student class and mark it static. You need to remember in the future that unfortunately C++ does not allow const static methods at this point of time, however. You will also only be able to manipulate "global", "file-scope static", or "static member data" variables.
That is petty much all about it. You could write this:
class MyClass {
public:
static int getNumStudents() { return totalStudentsCreated; }
};
Then you would call the method this way:
int numStudents = MyClass::getNumStudents();
or
int numStudents = myClass.getNumStudents();
Although, this latter may not work with all the compilers out there, so try to stick to the former variant.
Static function (without Class)
If you only need a static function without an external class, then you could write the following:
static int getNumStudents() { return totalStudentsCreated; }
and then use it as follows:
int numStudents = getNumStudents();