home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ for Dummies (3rd Edition)
/
C_FD.iso
/
CHAP14
/
CHAP14_1.CPP
next >
Wrap
C/C++ Source or Header
|
1996-09-02
|
920b
|
47 lines
// Chap14_1.cpp
#include <iostream.h>
#include <string.h>
class Student
{
public:
//conventional constructor
Student(char *pName = "no name", int ssId = 0)
{
cout << "Constructing new student " << pName << "\n";
strncpy(name, pName, sizeof(name));
name[sizeof(name) - 1] = '\0';
id = ssId;
}
//copy constructor
Student(Student &s)
{
cout << "Constructing Copy of " << s.name << "\n";
strcpy(name, "Copy of ");
strcat(name, s.name);
id = s.id;
}
~Student()
{
cout << "Destructing " << name << "\n";
}
protected:
char name[40];
int id;
};
//fn - receives its argument by value
void fn(Student s)
{
cout << "In function fn()\n";
}
int main()
{
Student randy("Randy", 1234);
cout << "Calling fn()\n";
fn(randy);
cout << "Returned from fn()\n";
return 0;
}