| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include<iostream.h> 
#include<string.h> 
class Y; 
class X 
{ 
        int x; 
        char *strx; 
public: 
        X(int a,char *str) 
        { 
                x=a; 
                strx=new char[strlen(str)+1]; 
                strcpy(strx,str); 
        } 
        void show(Y &ob); 
 
}; 
class Y 
{ 
        int y; 
        char *stry; 
public: 
        Y(int b,char *str) 
        { 
                y=b; 
                stry=new char[strlen(str)+1]; 
                strcpy(stry,str); 
        } 
        friend void X::show(Y &ob); 
}; 
void X::show(Y &ob) 
{ 
        cout<<"the string of X is:"<<strx<<endl; 
        cout<<"the string of Y is:"<<ob.stry<<endl; 
} 
void main() 
{ 
        X a(10,"stringx"); 
        Y b(10,"stringy"); 
        a.show(b); 
} 
 
 
 
今天弄了一天的友元类了,在遇到这个代码  都看不懂! 特别是(Y &ob)中的那个ob是哪里出来的? 这句到底想表达什么东西想不明白  还有最后一句  a.show(b)是怎么去实现的??? 一大堆问题  求大神救救我。。。在这样下去都不想学了。。。。求大神们帮帮我吧 谢谢谢谢!! 
 
 |   
 
 
 
 |