| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 427 人关注过本帖
标题:写了个关于友元成员函数的 运行的时候出错了.各位参谋下.
只看楼主 加入收藏
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
快速回复:写了个关于友元成员函数的 运行的时候出错了.各位参谋下.
数据加载中...
 
   



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

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