C++面向对象第十章.pptVIP

  • 2
  • 0
  • 约9.12千字
  • 约 57页
  • 2017-08-16 发布于浙江
  • 举报
C面向对象第十章

C++面向对象程序设计 第十章 类 葛勇 结构 回忆一下以前讲过的结构体。 struct words { char zimu; int num; }; int main() { words wd; wd.zimu=‘a’; wd.num=1; } 我们可以在一个程序中定义多个结构体,如: struct FertilizerStock { double quantity; double nitrogen_content; }; struct CropYield { int quantity; double size; }; int main() { FertilizerStock super_grow; super_grow.quantity=2.5; super_grow.nitrogen_content=5.3; CropYield apples; apples.quantity=3; apples.size=2.01; } 此外,两个同一类型的结构变量可以直接赋值,如: FertilizerStock f1; f1.quantity=2.3; f1. nitrogen_content=4.2; FertilizerStock f2=f1; 其中f2=f1;等价于: f2.quantity=f1.quantity; f2.nitrogen_

文档评论(0)

1亿VIP精品文档

相关文档