What is a scalar Object in C++?(什么是 C++ 中的标量对象?)
问题描述
据我所知,基本类型是标量,数组是聚合的,但用户定义的类型呢?我会根据什么标准将它们分为两类?
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;
推荐答案
简短版本: C++ 中的类型是:
Short version: Types in C++ are:
对象类型:标量、数组、类、联合
Object types: scalars, arrays, classes, unions
引用类型
函数类型
(成员类型)[见下文]
(Member types) [see below]
void
长版
对象类型
Object types
标量
算术(整数、浮点数)
arithmetic (integral, float)
指针:T * 用于任何类型 T
pointers: T * for any type T
枚举
成员指针
nullptr_t
数组:T[] 或 T[N] 用于任何完整的非引用类型 T
Arrays: T[] or T[N] for any complete, non-reference type T
类:class Foo 或 struct Bar
琐碎的课程
Trivial classes
聚合
POD 类
(等等等等)
联合:联合邮编
引用类型:T &、T && 用于任何对象或自由函数类型T
References types: T &, T && for any object or free-function type T
函数类型
自由函数:
R foo(Arg1, Arg2, ...)
成员函数:R T::foo(Arg1, Arg2, ...)
void
成员类型是这样工作的.成员类型的形式为 T::U,但您不能拥有成员类型的对象或变量.您只能拥有成员指针.成员指针具有类型 T::* U,如果 U 是(自由)对象类型,则它是指向成员对象的指针,并且指针-如果 U 是(自由)函数类型,则为成员函数.
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.
所有类型都是完整的,除了 void、未定义大小的数组和声明但未定义的类和联合.除了 void 之外的所有不完整类型都可以完成.
All types are complete except void, unsized arrays and declared-but-not-defined classes and unions. All incomplete types except void can be completed.
所有类型都可以const/volatile限定.
All types can be const/volatile qualified.
标头提供了 trait 类来检查这些类型特征中的每一个.
The <type_traits> header provides trait classes to check for each of these type characteristics.
这篇关于什么是 C++ 中的标量对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是 C++ 中的标量对象?
基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
