免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1266 | 回复: 1
打印 上一主题 下一主题

帮我看看这个程序怎么回事! type : 没有输出 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-09 12:30 |只看该作者 |倒序浏览
#include <iostream>
#include<cstring>
using namespace std;
enum Petstype {dog,cat,bird,fish};
class Pets
{
private:
        char *name;
        Petstype type;
public:
        Pets(const char *name ="sonny",Petstype type=dog);
        Pets& operator =(const Pets &s);
        ~Pets();
        void show() const;
};
Pets:ets(const char *name,Petstype)
{
        this->name=new char[strlen(name)+1];
        strcpy(this->name,name);
        this->type=type;
}
Pets::~Pets()
{
        delete[]name;
}
Pets& Pets:perator =(const Pets &s)
{
        if(&s==this) return *this;
        delete []name;
        name =new char[strlen(s.name)+1];
        strcpy(name,s.name);
                type=s.type;
        return *this;
}
void Pets::show() const
{
        cout<<"Name:"<<name<<"    type:";
        switch(type)
        {
        case dog:
                cout<<"dog";
                break;
        case cat:
                cout<<"cat";
                break;
        case bird:
                cout<<"bird";
                break;
        case fish:
                cout<<"fish";
                break;
        }
        cout<<endl;
}
int main()
{
        Pets mypet1,mypet2("john",dog);
        Pets youpet("Danny",cat);
        mypet1.show();
        mypet2.show();
        youpet.show();
        youpet=mypet2;
        youpet.show();
        return 0;
}

论坛徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52双子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午马
日期:2013-10-18 21:43:38
2 [报告]
发表于 2011-03-09 13:59 |只看该作者
构造函数定义改成:
  1. Pets::Pets(const char *name,Petstype type)
复制代码
你缺少了type
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP