第三章 类及对象2.pptVIP

  • 2
  • 0
  • 约1.53万字
  • 约 80页
  • 2017-06-17 发布于湖北
  • 举报
C++面向对象程序设计 3.4 对象数组 对象数组是指数组元素为对象的数组。 建立对象数组时,同样要调用构造函数。 如果构造函数只有一个参数,在定义数组时可以直接在等号后面的花括号内提供实参。 如果构造函数有多个参数,在花括号中分别写出构造函数并指定实参。 3.4 对象数组 #include iostream using namespace std; class Student {private: int number; public: Student(int n) //有1个参数的构造函数 { number=n; coutStudent(int n)endl; } Student() //无参数构造函数 { number=0; coutStudent()endl; } void Show() { coutnumber: numberendl; } ~Student(){cout“~Student”endl;} }; 3.4 对象数组 3.4 对象数组 3.4 对象数组 #include iostream using namespace std; class Box {public: Box(int h=10,int w=12,int len=15): height(h),width(w),length(len){ } int volu

文档评论(0)

1亿VIP精品文档

相关文档