首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于友元函数的一个有关问题

2012-03-26 
关于友元函数的一个问题#include iostream#include stringusingnamespacestdstructLib{//Libprivate:

关于友元函数的一个问题
#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里面........

热点排行