什么是C ++中的标量对象? [英] What is a scalar Object in C++?

查看:215
本文介绍了什么是C ++中的标量对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,基本类型是Scalar和Arrays是聚合的,但是用户定义的类型呢?我会以什么标准将它们分为两类?

  struct S {int i; int j}; 
class C {public:S s1_; S s2_};
std :: vector< int> V;
std :: vector< int> * pV =& v;


解决方案

in C ++ are:




  • 对象类型:标量,数组,类和联合

    b
  • 参考类型


  • 功能类型


  • )[参见下文]


  • void

    / ul>




    长版




    • 对象类型




      • 标量


        1. 算术(积分,浮点)


        2. 指针: T * 任何类型 T


        3. 枚举

          b
        4. 指向成员


        5. nullptr_t

          li>


      • 数组: T [] T对于任何完整的非引用类型 T


      • 类: class Foo struct Bar


        1. 小学课程


        2. 聚集



        3. (etc。



    • 引用类型: T& T&&&& 任何对象或自由功能类型 T


    • 函数类型




      • 自由函数: R foo(Arg1,Arg2 ,...)


      • 成员函数: RT :: foo(Arg1,Arg2, 。)



    • $ c>




    成员类型如下所示。成员类型的格式为 T :: U ,但不能有成员类型的对象或变量。您只能有成员指针。成员指针具有类型 T :: * U ,并且它是一个指向成员对象的指针,如果 U 是一个(自由)对象类型,如果 U 是一个(自由)函数类型,则指向成员函数的指针。



    所有类型都是完整的,除了 void ,未定义的数组和声明的但未定义的类和联合。除了 void 可以完成所有不完整的类型。



    所有类型都可以 const /



    code> header提供了trait类来检查每个类型的特征。


    As far as I understand it fundamental types are Scalar and Arrays are aggregate but what about user defined types? By what criteria would I divide them into the two categories?

    struct S { int i; int j };
    class C { public: S s1_; S s2_ };
    std::vector<int> V;
    std::vector<int> *pV = &v;
    

    解决方案

    Short version: Types in C++ are:

    • Object types: scalars, arrays, classes, unions

    • Reference types

    • Function types

    • (Member types) [see below]

    • void


    Long version

    • Object types

      • Scalars

        1. arithmetic (integral, float)

        2. pointers: T * for any type T

        3. enum

        4. pointer-to-member

        5. nullptr_t

      • Arrays: T[] or T[N] for any complete, non-reference type T

      • Classes: class Foo or struct Bar

        1. Trivial classes

        2. Aggregates

        3. POD classes

        4. (etc. etc.)

      • Unions: union Zip

    • References types: T &, T && for any object or free-function type T

    • Function types

      • Free functions: R foo(Arg1, Arg2, ...)

      • Member functions: R T::foo(Arg1, Arg2, ...)

    • void

    Member types work like this. A member type is of the form T::U, but you can't have objects or variables of member type. You can only have member pointers. A member pointer has type T::* U, and it is a pointer-to-member-object if U is a (free) object type, and a pointer-to-member-function if U is a (free) function type.

    All types are complete except void, unsized arrays and declared-but-not-defined classes and unions. All incomplete types except void can be completed.

    All types can be const/volatile qualified.

    The <type_traits> header provides trait classes to check for each of these type characteristics.

    这篇关于什么是C ++中的标量对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆