首页 > 编程语言 > 详细

c++结构体

时间:2019-11-29 23:10:55      阅读:90      评论:0      收藏:0      [点我收藏+]

结构体

  • c++中在声明结构变量时可以省略关键字struct;
  • 支持列表初始化,且=等号可省略。
    • 如果大括号中不包含任何东西,那么将所有值赋值为0。
    • 不允许缩窄转换。
  • 结构赋值
    • 将一个结构体变量赋给另一个结构体变量。
  • 可以在结构体定义之后直接声明该结构体的变量。
struct person
{
    int age;
    char name[12];
} my_smith;
my_smith.age = 22;
my_smith.car = "yangzixiong";
  • 匿名结构体
    • 这种结构体没有名称,后面就无法长久这种类型的变量。
    struct 
    {
      int age;
      char name[12];
    } p1;
    p1.age = 20;
    p1.name = "yangzixiong";
  • c++结构还可以有成员函数
  • 结构中的位字段。
    • 位字段通常用在低级编程中。
    • 具体应用暂时不知道。
    struct torgle_register
    {
      unsigned int SN : 4;
      unsigned int : 4;
      bool goodIn : 1;
      bool goodTorgle : 1;
    };
    torgle_register tr = { 14, true, false };

c++结构体

原文:https://www.cnblogs.com/yangzixiong/p/11960747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!