| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 758 人关注过本帖
标题:这段程序为什么不输出啊?
取消只看楼主 加入收藏
thlgood
Rank: 5Rank: 5
等 级:职业侠客
帖 子:281
专家分:381
注 册:2010-9-24
结帖率:91.43%
收藏
 问题点数:0 回复次数:2 
这段程序为什么不输出啊?
Windows 7下居然提示

程序代码:
#include <iostream>
#include <cstring>
using namespace std;

class Books
{
    private:
        float Price;
        string Author;
    public:
        Books(float price, string author);
        void ShowInfo();
        Books& operator =(const Books &bookname);
};

Books& Books::operator = (const Books &bookname)
{
    if (&bookname == this)
        return *this;
    else
    {
        Books temp(bookname.Price, bookname.Author);
        return temp;
    }
}

Books::Books(float price, string author)
{
    Price = price;
    Author = author;
}

void Books::ShowInfo()
{
    cout << "Book Price" << '\t' << Price << endl;
    cout << "Book Author" << '\t' << Author << endl;
}

int main()
{
    Books APEU(67, "Bob");
    APEU.ShowInfo();
    return 0;
}

搜索更多相关主题的帖子: Windows color price 
2011-11-04 20:45
thlgood
Rank: 5Rank: 5
等 级:职业侠客
帖 子:281
专家分:381
注 册:2010-9-24
收藏
得分:0 
回复 2楼 yuccn
谢谢。可是还是不能通过

o(∩∩)Linux & Python 群:187367181
2011-11-04 21:06
thlgood
Rank: 5Rank: 5
等 级:职业侠客
帖 子:281
专家分:381
注 册:2010-9-24
收藏
得分:0 
我该了一下,可还是不对

程序代码:
#include <iostream>
#include <string>
using namespace std;

class Books
{
    private:
        float Price;
        string Author;
    public:
        Books(float price, string author);
        void ShowInfo();
        Books operator =(const Books &bookname);
};

Books Books::operator = (const Books &bookname)
{
    if (&bookname == this)
        return *this;
    else
        return Books(bookname.Price, bookname.Author); //这里
}

Books::Books(float price, string author)
{
    Price = price;
    Author = author;
}

void Books::ShowInfo()
{
    cout << "Book Price" << '\t' << Price << endl;
    cout << "Book Author" << '\t' << Author << endl;
}

int main()
{
    Books APEU(67, "Bob");
    APEU.ShowInfo();
    return 0;
}


o(∩∩)Linux & Python 群:187367181
2011-11-04 21:28
快速回复:这段程序为什么不输出啊?
数据加载中...
 
   



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

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