Hello, as I'm on the run, I have no time to explain much.
I would like a class method (only one) to be able to access private data of another class. However, if I know how to make an entire class the friend of another class, I do not know how to do it for a single method
Ex:
class ABC {
public:
sing() {
say(song)
private:
string song = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
class ABCModify {
bool ChangeSong(string NewSong);
}
I want ABCModify::ChangeSong to be the friend of class ABC
Thanks in advance for any information
Class method as a friend of a class
Code: Select all
#include <stdio.h>
class ABC;
class ABCModify {
public:
bool ChangeSong(char * NewSong);
};
class ABC {
friend bool ABCModify::ChangeSong(char * NewSong);
public:
void sing(void) {
printf(song);
}
private:
char * song;
};
ABC test;
bool ABCModify::ChangeSong(char * NewSong) {
test.song = NewSong;
}
int main(int argc, char * argv[]) {
ABCModify x;
x.ChangeSong("beep");
test.sing();
}
Author of COBOS