- #include <iostream>
- using namespace std;
- class Internet;
- class Country
- {
- public:
- Country()
- {
- strcpy(cname,"中国");
- }
- void Editurl(Internet &temp);//成员函数的声明
- protected:
- char cname[30];
- };
- class Internet
- {
- public:
- Internet(char *name,char *address)
- {
- strcpy(Internet::name,name);
- strcpy(Internet::address,address);
- }
- friend void Country::Editurl(Internet &temp);//友元函数的声明
- protected:
- char name[20];
- char address[20];
- };
- void Country::Editurl(Internet &temp)//成员函数的外部定义
- {
- strcpy(temp.address,"edu.cndev-lab.com");
- cout<<temp.name<<"|"<<temp.address<<endl;
- }
- void main()
- {
- Internet a("中国软件开发实验室","www.cndev-lab.com");
- Country b;
- b.Editurl(a);
- cin.get();
- }
友元类分为三部分构成:
1,成员函数的申明
2,友元函数的申明
3,成员函数的外部定义