2017-04-20 3 views
-7

ここで私のコードはコードが完全でfriend関数を使用しようとしていますが、私の2番目のクラスのプライベートデータメンバーにアクセスすることができません

の私のクラスの私的メンバーにアクセスしようとしています
#include<iostream> 
#include<string> 
#include<fstream> 
using namespace std; 
class time; 
class date{ 
void friend mixdatetime(date &c, time &d); 
int day; 
int month; 
int year; 
public: 
date(int day, int month, int year){ 
    this->day = day; 
    this->month = month; 
    this->year = year; 
}}; 
class time{ 
int hours; 
int minutes; 
int seconds;  
public: 
time(int hours, int minutes, int seconds){ 
    this->hours = hours; 
    this->minutes = minutes; 
    this->seconds = seconds;} 
void print(){};} ; 
void mixdatetime(date &c, time &d){ 
c.day; // accessable 
// why //d.minutes // inacccess able };}; 

私はd.minutesまたはd.hoursにアクセスしようとしています//なぜアクセスできないのですか?私は親切にプライベートメンバにアクセス

+4

これはC#の権利とは関係ありません。なぜそれにタグを付けましたか? – DavidG

+2

[MCVE]とエラーを投稿し、コードを適切に書式設定してください。そして、タグをスパムしないでください。 –

+0

なぜ否定的な評価:3私はちょうど初心者ですbros:/間違ったタグを申し訳ありません –

答えて

1

はなぜアクセスできない

minutesので、クラスtimeにプライベートでd.minutes、あなたはクラスtimeの友人としてmixdatetimeを宣言していなかった私に、適切な解決策を伝えることができません。友だち宣言をクラスに追加してください:

friend void mixdatetime(date &c, time &d); 
関連する問題