CPP中原始数据类型的构造方法初始化 [英] Constructor Initialization of primitive data types in CPP

查看:125
本文介绍了CPP中原始数据类型的构造方法初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cpp中,我们可以将原始数据类型初始化为

In cpp, we can have primitive data-types initialized as

int a(32);

此构造函数初始化如何工作? C ++会将其视为对象吗?

How does this constructor initialisation work? Does C++ treat it as an object?

推荐答案

对此最好的描述是:

C ++ 03 8.5初始化程序
Para 12& 13:

.......
在新表达式(5.3.4),static_cast表达式(5.2.9),功能符号类型转换(5.2.3)以及基本和成员初始化程序(12.6.2)中发生的初始化称为
直接初始化,等效于形式

.......
The initialization that occurs in new expressions (5.3.4), static_cast expressions (5.2.9), functional notation type conversions (5.2.3), and base and member initializers (12.6.2) is called
direct-initialization and is equivalent to the form

T x(a);

如果T是标量类型,则声明形式为

If T is a scalar type, then a declaration of the form

T x = { a };

等效于

T x = a;

在问题中,类型为int,这是标量类型.

In the question the type is int which is a scalar type.

这篇关于CPP中原始数据类型的构造方法初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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