什么是“成员初始化器”在C ++ 11? [英] What is "member initializer" in C++11?

查看:156
本文介绍了什么是“成员初始化器”在C ++ 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个名为成员初始化程序的奇怪概念。

I run across a weird concept named "member initializer".

这里说:


C ++ 11添加了成员​​初始化程序,应用于成员的表达式$ b

C++11 added member initializers, expressions to be applied to members at class scope if a constructor did not initialize the member itself.

它的定义是什么?

有一些例子来说明其用法吗?

Are there some examples to illustrate its usage?

推荐答案

初始化器。这允许您在声明时初始化非静态数据成员:

It probably refers to in-class member initializers. This allows you to initialize non-static data members at the point of declaration:

struct Foo
{
  explicit Foo(int i) : i(i) {} // x is initialized to 3.1416
  int i = 42;
  double x = 3.1416;
};

更多关于 Bjarne Stroustrup的C ++ 11常见问题

这篇关于什么是“成员初始化器”在C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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