标题:友元问题 在执行的时候出现错误(DC++和VC++6.0)
取消只看楼主
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
结帖率:53.85%
已结贴  问题点数:20 回复次数:3 
友元问题 在执行的时候出现错误(DC++和VC++6.0)
#include<iostream>
#include<string.h>

using namespace std;

class person;
class spouse
{
    private:
        person *phusband;
        person *pwife;
    public:
        spouse(const person &hus,const person &wf);
        void Show()const;
        ~spouse(){
            delete phusband;
            delete pwife;
        }
        
        
};
class person
{
    private:
        char *name;
        int age;
        char sex[6];
    public:
        person(char *n,int a,char *s):age(a)
        {
            strcpy(name,n);strcpy(sex,s);
        }
        
        void Show()const{
            cout<<name<<""<<age<<sex<<endl;
        }
        friend void spouse::Show() const;
        
};
spouse::spouse(const person &hus,const person &wf)
{
    phusband=new person(hus);
    pwife=new person(wf);
   
}
void spouse::Show()const
{
    cout<<"丈夫:"<<phusband->name<<phusband->age<<phusband->sex<<endl;
    cout<<"妻子:"<<pwife->name<<pwife->age<<pwife->sex<<endl;
}
int main()
{
    person husband("张强",32,"男");
    person wife("吴珊",28,"女");
    spouse sp(husband,wife);
   
   
    wife.Show();
    husband.Show();
    sp.Show ();
    system("pause");
    return 0;
}
搜索更多相关主题的帖子: private include person public 
2016-03-22 13:46
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
得分:0 
回复 2楼 牧羊人94
friend void spouse::Show() const;
我把他改成friend class spouse;
但是仍然不行。
2016-03-22 21:16
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
得分:0 
回复 4楼 TonyDeng
这是我们教材上的代码,学习友元函数,。
2016-03-22 21:33
winnie96
Rank: 2
等 级:论坛游民
帖 子:51
专家分:86
注 册:2015-12-14
得分:0 
回复 10楼 牧羊人94
谢谢你啦!!!
2016-03-23 22:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-462773-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.525523 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved