打的第一个C++程序。编译不通过
[code=C/C++][/code#include<iostream>
using namespace std;
class Box
{
private:
int length,width,height,volume;
void vprint();
public:
void volume(int nlength,int nwidth,int nheight);
};
void Box::volume(int nlength,int nwidth,int nheight)
{
length=nlength;
width=nwidth;
height=nheight;
}
void Box::vprint()
{
volume=length*width*height;
cout<<volume<<endl;
}
void main()
{
Box a;
int l,w,h;
cout<<"请输入长宽高:"<<endl;
cin>>l>>w>>h;
a.volume(l,w,h);
a.vprint();
}]
[解决办法]
volume变量名于函数名重复。
[解决办法]
- C/C++ code
//2个问题私有成员和函数名重名(volume),a.vprint();私有不可调用
[解决办法]
输入是多少?输出是多少?