|
Real object oriented programming or OOP as it is sometimes called by programming Geeks, with just a bit of humor, is much more than just programming with classes. It is a different way of thinking.
|




class time_class
{
private:
long m_lSecs;
friend char *presentTime(time_class tz);
public:
time_class(char *t);
~time_class();
}
The following code shows how you might define the function presentTime. It can be in
the same file with main() or it can be in the time_class.cpp file, but not defined as part
of the class, i.e. it does not have time_class:: in its heading.
char *presentTime(time_class tz)
{
char *ctbuf;
ctbuf = new char[40];
long seconds_total;
seconds-total = tz. m_lSecs;
ltoa(seconds_total, ctbuf, 10); // long to ascii function found in stdlib.h
return ctbuf;
}
The function presentTime() is external to the class, but by defining it as a friend of
the class it is permitted to directly access the m_lSecs private member variable.





