-7
我想通过下面的朋友功能访问该类的私人成员我的代码是完整的代码我想使用朋友功能,但我无法访问我的第二类的私人数据成员
#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 //我不能,因为它无法访问为什么?我无法访问私有成员请你告诉我合适的解决方案
所以这与C#无关吗?你为什么要标签? – DavidG
请发布[MCVE],错误并正确设置代码格式。并且不要垃圾邮件标签。 –
为什么负面评价:3我只是一个初学者兄弟:/对不起,错误的标记 –