关于友元函数的一个问题
#include <iostream>
#include <string>
using namespace std;
struct Lib{ //Lib
private:
string a;
public:
void seta(string i);
string geta();
};
void Lib::seta(string i){
a=i;
}
string Lib::geta(){
return a;
}
struct Libc{ //Libc
friend void geta();
};
int main(){
Libc Y;
Lib X;
X.seta( "Hello World! ");
cout < <Y.geta() < <endl;
}
在Libc中声明了geta()是友元函数了,为什么不能访问呢
出现35 'struct Libc ' has no member named 'geta ' 这样的错误
[解决办法]
struct Libc中用lib的东西
是lib给libc开个窗口
友元的声明也要放在lib里面........