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

帮忙指出异常指点指点谢了

2012-04-15 
帮忙指出错误指点指点谢了#includeiostreamusing namespace stdclass X{private:static int ifriend c

帮忙指出错误指点指点谢了
#include<iostream>
using namespace std;
class X{
  private:
  static int i;
  friend class Z;
  friend void h(X&x1);
  friend void g(X&x3);
  }
  class Z{
  public:
  void f(X&x2);
  }
  class Y{
  public:
  void g(X&x3);
  }
  void h(X&x1){
  cout<<"friend h i="<<x1.i+5;
  }
  void Y::g(X&x3){
  cout<<"friend g i="<<x3.i++;
  }
  void Z::f(X&x2){
  cout<<"friend f i="<<x2.i+10;
  }
  int main(){
  X x1,x2,x3;
  h(x1);
  Y y;
  y.g(x3);
  Z z;
  z.f(x2);
  system("pause");
  return 0;
  }
   
   


[解决办法]

C/C++ code
#include<iostream>using namespace std;class X{ // private:  public : //static成员属于整个类,需要定义public的          static int i;  friend class Z;  friend void h(X&x1);  friend void g(X&x3);  }; //需要加;的哈     //static成员需要在类外面定义    int X::i = 0;    class Z{  public:  void f(X&x2);  };     class Y{  public:  void g(X&x3);  };  void h(X&x1){  cout<<"friend h i="<<x1.i+5;  }  void Y::g(X&x3){  cout<<"friend g i="<<x3.i++;  }  void Z::f(X&x2){  cout<<"friend f i="<<x2.i+10;  }    int main(){  X x1,x2,x3;  h(x1);  Y y;  y.g(x3);  Z z;  z.f(x2);  system("pause");  return 0;  } 

热点排行