C++之用参数初始化表对数据成员初始化

#include <iostream>


using namespace std;


struct Box
{
public:
Box(int len,int w,int h):length(len),width(w),height(h){}
int volume();
private:
int length;
int width;
int height;
};


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/80292540