| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 529 人关注过本帖
标题:关于c++友元类的错误
取消只看楼主 加入收藏
wghost
Rank: 2
等 级:论坛游民
帖 子:47
专家分:31
注 册:2009-6-6
结帖率:37.5%
收藏
已结贴  问题点数:16 回复次数:1 
关于c++友元类的错误
//Time.h
class Date;
class Time  
{
public:
    Time(int,int,int );
    void display(const Date&);
    virtual ~Time();
private:
    int hour;
    int minute;
    int sec;

};
//Date.h
class Time;
class Date  
{    friend  class Time;
public:
    Date(int,int,int);

    virtual ~Date();
private:
    int month;
    int day;
    int year;
};
//Time.cpp
Time::Time(int h,int m,int s)
{
 hour=h;
 minute=m;
 sec=s;
}

Time::~Time()
{

}
void display( const Date & d)
{
    cout<<d.month<<"/"<<d.day<<"/"<<d.year<<endl;
    cout<<hour<<"/"<<minute<<"/"<<sec<<endl;
}
//Date.cpp
Date::Date(int m,int d,int y)
{
 month=m;
 day=d;
 year=y;
}

Date::~Date()
{

}
//主函数
#include"Date.h"
#include"Time.h"
int main()
{
    Time t1(10,13,56);
    Date d1(12,15,2004);
    t1.display(d1);
    return 0;
}
我用的是vc++环境为什么总提示下列错误啊,各位高手多指教啊
Compiling...
Time.cpp
D:\c++\ex3_h11\Time.cpp(26) : error C2248: 'month' : cannot access private member declared in class 'Date'
        d:\c++\ex3_h11\date.h(21) : see declaration of 'month'
D:\c++\ex3_h11\Time.cpp(26) : error C2248: 'day' : cannot access private member declared in class 'Date'
        d:\c++\ex3_h11\date.h(22) : see declaration of 'day'
D:\c++\ex3_h11\Time.cpp(26) : error C2248: 'year' : cannot access private member declared in class 'Date'
        d:\c++\ex3_h11\date.h(23) : see declaration of 'year'
D:\c++\ex3_h11\Time.cpp(27) : error C2065: 'hour' : undeclared identifier
D:\c++\ex3_h11\Time.cpp(27) : error C2065: 'minute' : undeclared identifier
D:\c++\ex3_h11\Time.cpp(27) : error C2065: 'sec' : undeclared identifier
Error executing cl.exe.

搜索更多相关主题的帖子: private display public friend minute 
2009-10-31 20:23
wghost
Rank: 2
等 级:论坛游民
帖 子:47
专家分:31
注 册:2009-6-6
收藏
得分:0 
谢啦!!
2009-11-04 10:33
快速回复:关于c++友元类的错误
数据加载中...
 
   



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

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