zoukankan      html  css  js  c++  java
  • Incomplete types-不完全类型

    另外:前向声明中引入的类型为不完全类型(incomplete type),不完全类型只能以有限方式使用,只能用于定义指向该对象的指针和引用,只能用于声明使用该类型作为形参或返回类型的函数。

    Incomplete types[edit]

    An incomplete type is a structure or union type whose members have not yet been specified, an array type whose dimension has not yet been specified, or the void type (the void type cannot be completed). Such a type may not be instantiated (its size is not known), nor may its members be accessed (they, too, are unknown); however, the derived pointer type may be used (but not dereferenced).

    They are often used with pointers, either as forward or external declarations. For instance, code could declare an incomplete type like this:

    struct thing *pt;
    

    This declares pt as a pointer to struct thing and the incomplete type struct thing. Pointers to data always have the same byte-width regardless of what they point to, so this statement is valid by itself (as long as pt is not dereferenced). The incomplete type can be completed later in the same scope by redeclaring it:

    struct thing {
        int num;
    }; /* thing struct type is now completed */
    

    Incomplete types are used to implement recursive structures; the body of the type declaration may be deferred to later in the translation unit:

    typedef struct Bert Bert;
    typedef struct Wilma Wilma;
    
    struct Bert {
        Wilma *wilma;
    };
    
    struct Wilma {
        Bert *bert;
    };
    

    Incomplete types are also used for data hiding; the incomplete type is defined in a header file, and the body only within the relevant source file.

    https://en.wikipedia.org/wiki/C_syntax#Incomplete_types

  • 相关阅读:
    Dynamics CRM 给视图配置安全角色
    统计分析中的假设检验
    OLAP工作的基本概念(结合个人工作)
    Dynamics CRM 导入用户数据错误 could not retrieve salesperson role
    HTTP状态码汇总
    HTTP状态码汇总
    PHP超级全局变量——Session 变量
    PHP超级全局变量——Session 变量
    RESTful架构详解
    RESTful架构详解
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8671749.html
Copyright © 2011-2022 走看看