#include <iostream.h>
#include <string.h>
class Student
{
public:
Student(char *pName = "no name")      //constructor
                                     //("no name" is default value)
  {
  strcpy(name, pName);
  noOfStudents++;
  }
~Student()                            //destructor (see Lecture 4)
  {
    noOfStudents--;
  }
 //findName - return student with specified name
   static Student *findname(char *pName);
private:
static int noOfStudents;
static Student *pFirst;
Student *pNext;
char name[40];
};
int Student::noOfStudents=0;     //Initialize static data member
Student* Student::pFirst=0;      //Initialize static data member
//findName- return student with specified name.
//          Return zero if no match.
Student* Student::findName(char *pName)
{
//loop through linked list...
for(Student *pS=pFirst; pS; pS = pS->pNext)
{
  //if we find the specified name...
  if(strcmp(pS->name, pName) == 0)
    {
      //then return the object's address
      return pS;
    }
}
//otherwise, return a zero (item not found)

return (Student*)0;              //cast
}
int main()
{
Student s1("Randy");
Student s2("Jenny");
Student s3("Susy");
Student *pS = Student::findName("Jenny");
return 0;
}

No default object is associated with a static member function. Calling the static member function with an object doesn’t help. For example:

//...same as before...
int main()
{
Student s1("Randy");
Student s2("Jenny");
Student s3("Susy");
Student *pS = s1.findName("Jenny");
return 0;
}

The s1 is not evaluated and not passed to findName(). Only its class is used to decide which findName() to call.