C++之带参数的构造函数(类外定义)

#include <iostream>


using namespace std;


struct Box
{
public:
Box(int,int,int); //声明带参数的构造函数 
int volume();
private:
int length;
int width;
int height;
};


Box::Box(int len,int w,int h)
{
height=h;
width=w;
length=len;
}


int Box::volume()
{
return (length*width*height);
}


int main()
{
Box b1(10,10,10);
cout<<"volume="<<b1.volume()<<endl;

return 0;
}

猜你喜欢

转载自blog.csdn.net/wrc_nb/article/details/80292495