{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/cpp-struct/",
  "atlas": "https://www.pystone.net/?node=cpp-struct#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/cpp-struct.md",
  "context": "https://www.pystone.net/notes/cpp-struct.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:cpp-struct",
  "slug": "cpp-struct",
  "title": "结构体",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "结构体 C++结构体与类的区别",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "updatedAt": "2023-07-25T13:44:50.000001Z",
  "contentHash": "b12c7353c526b4e9211cbd0cc977f04168d9cdc5222e6da42c760800b3acc729",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "结构体",
      "anchor": "结构体",
      "citation": "https://www.pystone.net/notes/cpp-struct/#%E7%BB%93%E6%9E%84%E4%BD%93"
    },
    {
      "depth": 2,
      "text": "C++结构体与类的区别",
      "anchor": "c结构体与类的区别",
      "citation": "https://www.pystone.net/notes/cpp-struct/#c%E7%BB%93%E6%9E%84%E4%BD%93%E4%B8%8E%E7%B1%BB%E7%9A%84%E5%8C%BA%E5%88%AB"
    },
    {
      "depth": 2,
      "text": "C与C++结构体区别",
      "anchor": "c与c结构体区别",
      "citation": "https://www.pystone.net/notes/cpp-struct/#c%E4%B8%8Ec%E7%BB%93%E6%9E%84%E4%BD%93%E5%8C%BA%E5%88%AB"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/cpp-struct/#ref"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "C++中的“结构体”导航项",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#c"
    }
  ],
  "contentMarkdown": "# 结构体\n## C++结构体与类的区别\n\n结构体和类的唯一区别就是： 结构体和类具有不同的**默认访问控制属性**。\n\n类中，对于未指定访问控制属性的成员，其访问控制属性为私有类型（private）\n\n结构体中，对于未指定任何访问控制属性的成员，其访问控制属性为公有类型（public）\n\n\n## C与C++结构体区别\n\nC语言中结构体不允许定义函数成员，且没有访问控制属性的概念。\n\n\n- C++为C语言中的结构体引入了成员函数、访问控制权限、继承、包含多态等面向对象特性。\n- C++在struct之外引入了class关键字，但为了保持与C程序的兼容，C++保留了struct关键字，并规定结构体默认访问控制权限为公有类型。\n- C语言中，空结构体的大小为0，而C++中空结构体（属于空类）的大小为1。\n\n> C++中空类的大小为1的原因：\n>\n> 空类也可以实例化，类实例化出的每个对象都需要有不同的内存地址，为使每个对象在内存中的地址不同，所以在类中会加入一个隐含的字节。\n\n\n## Ref\n\n<https://www.cnblogs.com/Carrie-0173/p/6357715.html>\n"
}
