home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ for Dummies (3rd Edition)
/
C_FD.iso
/
CHAP14
/
CHAP14_2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-02
|
1KB
|
53 lines
// Chap14_2.cpp
#include <iostream.h>
#include <string.h>
class Student
{
public:
Student(char *pName = "no name")
{
cout << "Constructing new student " << pName << "\n";
strncpy(name, pName, sizeof(name));
name[sizeof(name) - 1] = '\0';
}
Student(Student &s)
{
cout << "Constructing Copy of " << s.name << "\n";
strcpy(name, "Copy of ");
strcat(name, s.name);
}
~Student()
{
cout << "Destructing " << name << "\n";
}
protected:
char name[40];
};
class Tutor
{
public:
Tutor(Student &s) : student(s) //invoke copy constructor...
{ //...on member student
cout << "Constructing tutor\n";
}
protected:
Student student;
};
void fn(Tutor tutor)
{
cout << "In function fn()\n";
}
int main()
{
Student randy("Randy");
Tutor tutor(randy);
cout << "Calling fn()\n";
fn(tutor);
cout << "Returned from fn()\n";
return 0;
}