标题:写了个关于友元成员函数的 运行的时候出错了.各位参谋下.
只看楼主
liuweizwh
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-3-23
结帖率:0
 问题点数:0 回复次数:1 
写了个关于友元成员函数的 运行的时候出错了.各位参谋下.
#include<iostream>
#include<string>
using namespace std;
class Student;
class Date
{
private:
    int year,month,day;
public:
    Date(int y,int m,int d);
    void display(const Student &stu);
};
class Student
{
private:
    char *specialty;
public:
    Student (char *pspec);
    ~Student();
    friend void Date::display(const Student &);
};
Date::Date(int y,int m,int d)
{
    cin>>y>>" ">>m>>" ">>d;
    year=y;
    month=m;
    day=d;
}
void Date::display(const Student &stu)
{
    cout<<stu.specialty<<endl;
    cout<<year<<" "<<month<<" "<<day<<endl;
}
Student::Student(char *pspec)
{
    if(pspec)
    {
        specialty=new char[strlen(pspec)+1];
        strcpy(specialty,pspec);
    }
    else specialty=0;
}
Student::~Student()
{
    if(specialty)
        delete []specialty;
    else specialty=0;
}

int main()
{
    int y,m,d;
    cin>>y>>" ">>m>>" ">>d;
    Student zhang ("computer");
    Date birthday (y,m,d);
    birthday. display (zhang);
    return 0;
}
 运行的时候我输入日期 按回车 然后就突然中止了



















搜索更多相关主题的帖子: void specialty private display 
2013-05-05 13:31
liuweizwh
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-3-23
得分:0 
自己解决了
2013-05-05 13:48



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




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

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