对象的赋值
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 class Box 6 { 7 public: 8 Box(int=10,int=10,int=10); 9 int volume(); 10 private: 11 int height; 12 int width; 13 int length; 14 }; 15 Box::Box(int h,int w,int len) 16 { 17 height=h; 18 width=w; 19 length=len; 20 } 21 int Box::volume() 22 { 23 return(height*width*length); 24 } 25 int main(int argc, char** argv) { 26 Box box1(15,30,25),box2; 27 cout<<"The volume of box1 is "<<box1.volume()<<endl; 28 box2=box1; 29 cout<<"The volume of box2 is "<<box2.volume()<<endl; 30 return 0; 31 }