C++之帶引數的建構函式(類外定義)
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;
}