C++编程思想 第1卷 第3章 创建复合类型 用struct把变量结合在一起 typedef

定义s1和s2时,通过这样使用typedef,可以假定Structure2是一个像int或float一样的内建类型

sturct标识已经脱离原来的目的,这里的目的是创建typedef


//: C03:SimpleStruct2.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Using typedef with struct
typedef struct {
  char c;
  int i;
  float f;
  double d;
} Structure2;

int main() {
  Structure2 s1, s2;
  s1.c = 'a';
  s1.i = 1;
  s1.f = 3.14;
  s1.d = 0.00093;
  s2.c = 'a';
  s2.i = 1;
  s2.f = 3.14;
  s2.d = 0.00093;
} ///:~

无输出


猜你喜欢

转载自blog.csdn.net/eyetired/article/details/80715536