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

下面是小弟的代码,实在找不出有关问题,请高手们帮忙

2012-04-15 
下面是小弟的代码,实在找不出问题,请高手们帮忙求长方住的体积//volume.h#includeiostreamusing namespa

下面是小弟的代码,实在找不出问题,请高手们帮忙
求长方住的体积

//volume.h
#include<iostream>
using namespace std;
class volume

public:
  void set_value();
  void multi_value();
void show_value();
private:
  int length;
  int width;
  int height;
int result;
};

//volume.cpp

#include<iostream>
#include"volume.h"

void volume::set_value()
{ int i=0;
  for(;i<3;i++)
  {
  cin>>length;
  cin>>width;
  cin>>height;
  };
}
void volume::multi_value()
{  
result=length*width*height;
}

void volume::show_value()
{  
cout<<result<<endl;
}

int main()
{ volume v[3];
  int j=0;
  for(;j<3;j++) v[j].set_value();
  for(j=0;j<3;j++) v[j].multi_value();
  cout<<v[0].result<<" "<<v[1].result<<" "<<v[2].result<<endl;
  return 0;
}
   
debug: cpp(28) : error C2248: 'result' : cannot access private member declared in class 'volume'
  d:\程序\volume\volume.h(13) : see declaration of 'result'
d:\程序\volume\volume.cpp(28) : error C2248: 'result' : cannot access private member declared in class 'volume'
  d:\程序\volume\volume.h(13) : see declaration of 'result'
d:\程序\volume\volume.cpp(28) : error C2248: 'result' : cannot access private member declared in class 'volume'
  d:\程序\volume\volume.h(13) : see declaration of 'result'
Error executing cl.exe.


[解决办法]
v[0].result。。。。result是私有成员。。外部不能对其进行直接操作。。你要写一个函数。。用于输出result

热点排行