//友元的应用,成员类与列表类的浑然天成
class Personnel
{
friend class point_list; //用来实现输出链表,以及插入或删除人员的功能.
protected:
char serial_number[15];//编号
char name[10];//名称
char password[15]//口令
Personnel *pointer;
Personnel *next_link;
public:
Personnel(char *sn,char *nm,char *pwd)
{
strcpy(serial_number,sn);
strcpy(name,sm);
strcpy(password,pwd);
next_link=0;
}
Personnel()
{
serial_number[0]=NULL;
name[0]=NULL;
password[0]=NULL;
next_link=0;
}
void fill_serial_number(char *p_n)
{
strcpy(serial_number,p_n);
}
void fill_name(char *p_nm)
{
strcpy(name,p_nm);
}
void fill_password(char *p_pwd)
{
strcpy(password,p_pwd);
}
virtual void addnew(){}
virtual void display()
{
cout<<"\n编号:"< cout<<"名字:"< cout<<"口令:"< }
};
//实现友元类
class point_list
{
private:
Personnel *location;
public:
point_list()
{
location=0;
}
void print();
void insert(Personnel *node);
void delete(char *serial_number);
}
//显示链表
void point_list::print()
{
Personnel *ps=location;
while(ps!=0)
{
ps->display();
ps=ps->next_link; //可以直接调用基类中的protect的成员函数。
}
}
阅读(1318) | 评论(0) | 转发(0) |