| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1079 人关注过本帖
标题:谁能帮我改改,好多错误==
只看楼主 加入收藏
Orphan
Rank: 1
来 自:僵尸大
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-5-21
结帖率:0
收藏
已结贴  问题点数:10 回复次数:13 
谁能帮我改改,好多错误==
#include<iostream>
using namespace std;
class date
{protected:
        int year;
    int month;
    int day;
 public:
    date(inty,intm,int d)
    {
        year=y;
        month=m;
        day=d;
   
    }
    void display()
    {
    cout<<year<<"/"<<month<<"/"<<day<<endl;
    }

};
class person
{protected:
    string name;
 public:
    person(string n)
    {
        name=n;
    }
    void display()
    {
        cout<<name<<endl;
    }

};
class student : public person
{protected:
    date=birthday;
public:
    student(date d,string n):person(n)
    {
    birthday=d;
    }
    void display()
    {
    cout<<name;
    birthday.display();
    }

};
int main()
{
        int y,m,d;
    cin>>y>>m>>d;
    date d(y,m,d);
    d.display();
    person p("xiaoming",d):student s(d,"xiaoming");
    s.display();
    return 0;
}


//--------------------Configuration: ksd - Win32 Debug--------------------
Compiling...
dzwee.cpp
E:\\ksd\dzwee.cpp(32) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,structstd::char_traits<char>,class std::allocator<char>>' (or there is no acceptable conversion)
E:\\ksd\dzwee.cpp(38) : error C2059: syntax error : '='
E:\\ksd\dzwee.cpp(38) : error C2238: unexpected token(s) preceding ';'
E:\\ksd\dzwee.cpp(55) : error C2371: 'd' : redefinition; different basic types
        E:\\ksd\dzwee.cpp(53) : see declaration of 'd'
E:\\ksd\dzwee.cpp(56) : error C2228: left of '.display' must have class/struct/union type
E:\\ksd\dzwee.cpp(57) : error C2143: syntax error : missing ';' before ':'
E:\\ksd\dzwee.cpp(58) : error C2065: 's' : undeclared identifier
E:\\ksd\dzwee.cpp(58) : error C2228: left of '.display' must have class/struct/union type
执行 cl.exe 时出错.

dzwee.obj - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: display include person public 
2015-06-05 15:07
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:2 
这都是神马  date(inty,intm,int d)

DO IT YOURSELF !
2015-06-05 15:12
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:2 
改代码容易,改习惯难啊!
程序代码:
#include<iostream> 
using namespace std;
class date{
protected:
    int year;
    int month;
    int day;
public:
    date(){
        year=2015;
        month=6;
        day=1;
    }
    date(int y,int m,int d){
        year=y;
        month=m;
        day=d;
    }
    void display(){
        cout<<year<<"/"<<month<<"/"<<day<<endl;
    }

};
class person{
protected:
    string name;
public:
    person(string n){
        name=n;
    }
    void display(){
        cout<<name<<endl;
    }
};
class student : public person{
protected:
    date birthday;
public:
    student(date d,string n):person(n){
        birthday=d;
    }
    void display(){
      cout<<name;
      birthday.display();
    }
};
int main(){
    int y,m,d;
    cout<<"year:";
    cin>>y;
    cout<<"month:";
    cin>>m;
    cout<<"day:";
    cin>>d;
    date dt(y,m,d);
    dt.display();
    person p("xiaoming");
    student s(dt,"xiaoming");
    p.display();
    s.display();
    return 0;
}

剑栈风樯各苦辛,别时冰雪到时春
2015-06-05 15:38
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:2 
无数的低级错误。
楼主,我猜你从来没上过课或看过书

程序代码:
#include <iostream>
#include <string>

class date
{
public:
    date( unsigned year, unsigned month, unsigned day ) : year_(year), month_(month), day_(day)
    {
    }
protected:
    unsigned year_, month_, day_;

    friend std::ostream& operator<< ( std::ostream& os, const date& d );
};

std::ostream& operator<< ( std::ostream& os, const date& d )
{
    return os << d.year_ << '/' << d.month_ << '/' << d.day_;
}

class person
{
public:
    person( const char* name ) : name_(name)
    {
    }
    virtual ~person()
    {
    }
protected:
    std::string name_;

    friend std::ostream& operator<< ( std::ostream& os, const person& p );
};

std::ostream& operator<< ( std::ostream& os, const person& p )
{
    return os << p.name_;
}

class student : public person
{
public:
    student( const date& birthday, const char* name ) : person(name), birthday_(birthday)
    {
    }
protected:
    date birthday_;

    friend std::ostream& operator<< ( std::ostream& os, const student& s );
};

std::ostream& operator<< ( std::ostream& os, const student& s )
{
    return os << static_cast<const person&>(s) << '\n' << s.birthday_;
}

using namespace std;

int main( void )
{
    unsigned y, m, d;
    cin >> y >> m >> d;

    date birthday( y, m, d );
    cout << birthday << endl;

    student s( birthday, "xiaoming" );
    cout << s << endl;

    return 0;
}

2015-06-05 15:42
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:2 
楼主要学会看编译信息,不懂的单词要查一查,时间长了就能根据编译信息改正大部分错误

一片落叶掉进了回忆的流年。
2015-06-05 18:18
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:2 
楼主如果觉得自己错误多了改不过来的话,给你个建议,先写短一些的代码,比如只写一个类,只调用该类的功能摆弄一下。感觉没问题了再新建个工程写另一个类。所有可能存在的问题分别搞好了再把不同的类用在一个工程里。对自己语法还不太自信的情况下最好不要一口吃个胖子。一步步慢慢来更容易解决问题,也有利于提高自己信心。
    再有就是如5楼所说,自己多琢磨一下编译信息。
    其实编程中遇到的最可怕问题根本不是你这些语法错误,而是编译运行顺利通过,却没出现自己想要的结果。
2015-06-05 23:00
Orphan
Rank: 1
来 自:僵尸大
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-5-21
收藏
得分:0 
回复 6楼 yangfrancis
谢谢你的建议,可是我看不出来= =||

[i]其实我们都一样,一样想和大多数人不一样。[i]
2015-06-06 18:28
Orphan
Rank: 1
来 自:僵尸大
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-5-21
收藏
得分:0 
回复 5楼 诸葛欧阳
可是我看不出来,英文单词一定要正确吗,好忧伤

[i]其实我们都一样,一样想和大多数人不一样。[i]
2015-06-06 18:34
Orphan
Rank: 1
来 自:僵尸大
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-5-21
收藏
得分:0 
回复 4楼 rjsp
只是没有听= =

[i]其实我们都一样,一样想和大多数人不一样。[i]
2015-06-06 18:35
Vsnow
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:124
专家分:145
注 册:2015-1-3
收藏
得分:2 
英文单词的正确那肯定是必须的啊!就连符号都不能有错呐
2015-06-06 23:37
快速回复:谁能帮我改改,好多错误==
数据加载中...
 
   



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

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