| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 501 人关注过本帖
标题:关于类的问题
只看楼主 加入收藏
mghxz252
Rank: 2
等 级:论坛游民
帖 子:40
专家分:60
注 册:2010-1-18
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:3 
关于类的问题
下面这个程序是我按书上的来写的,怎么运行不出来啊??
顺便说一下,我用的是Dev-C++。
谢谢。
#include <iostream.h>
class family
{
      private:
              char *husband;
              char *wife;
              char *son;
              char *daughter;
              family *ptr;
              public:
                     void initialize(void);
                     friend void output(family *ptr);
                     }
                     family Anderson;
                     void output(family *ptr);
                     main(void)
                     {
                               Anderson.initialize();
                               }
                               void family::initialize(void)
                               {
                                    Anderson.ptr=&Anderson;
                                    ptr->husband="John Anderson";
                                    ptr->wife="Mary Anderson";
                                    ptr->son="Joey Anderson";
                                    ptr->daughter="Marla Anderson";
                                    output(ptr);
                                    }
                                    void output(family *ptr)
                                    {
                                         cout<<"husband is "<<ptr->husband<<"\n"
                                         <<"wife is "<<ptr->wife<<"\n"
                                         <<"son is "<<ptr->son<<"\n"
                                         <<"daughter is"<<ptr->daughter<<"\n"
                                         }
                                    
搜索更多相关主题的帖子: include private husband void 
2010-03-11 11:30
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:20 
没有什么大问题!
程序代码:
#include <iostream>
using namespace std;
class family
{
private:
    char *husband;
    char *wife;
    char *son;
    char *daughter;
    family *ptr;
public:
    void initialize(void);
    friend void output(family *ptr);
};
family Anderson;
void output(family *ptr);
main(void)
{
    Anderson.initialize();
}
void family::initialize(void)
{
    Anderson.ptr=&Anderson;
    ptr->husband="John Anderson";
    ptr->wife="Mary Anderson";
    ptr->son="Joey Anderson";
    ptr->daughter="Marla Anderson";
    output(ptr);
}
void output(family *ptr)
{
    cout<<"husband is "<<ptr->husband<<"\n"
    <<"wife is "<<ptr->wife<<"\n"
    <<"son is "<<ptr->son<<"\n"
    <<"daughter is"<<ptr->daughter<<"\n";
}

★★★★★为人民服务★★★★★
2010-03-11 13:32
mghxz252
Rank: 2
等 级:论坛游民
帖 子:40
专家分:60
注 册:2010-1-18
收藏
得分:0 
可是我一直编译都是出错的,难道是编译器的问题??
2010-03-11 14:43
mghxz252
Rank: 2
等 级:论坛游民
帖 子:40
专家分:60
注 册:2010-1-18
收藏
得分:0 
搞定了,谢谢二楼的。
2010-03-11 14:48
快速回复:关于类的问题
数据加载中...
 
   



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

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