Hi, i can't type y.note in ***** section. How can I do this with friend class?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
using namespace std;
class classroom
{
private:
int note;
public:
void takenote(int x)
{
note = x;
}
friend int shownote(classroom y);
};
int shownote(classroom y)
{
y.*****
}
int main()
{
}
|
Last edited on
goster is not a friend of classroom.
sorry my mistake, but still the same
It seems to work fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
class classroom
{
private:
int note;
public:
void takenote(int x)
{
note = x;
}
friend int shownote(classroom y);
};
int shownote(classroom y)
{
std::cout << y.note << '\n';
return 0;
}
int main()
{
classroom cr;
cr.takenote(105);
shownote(cr);
}
|
105 |
Last edited on