C ++中的默认结构初始化 [英] Default Struct Initialization in C++

查看:217
本文介绍了C ++中的默认结构初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个像这样的结构(POD):

Say I have a struct that looks like this (a POD):

struct Foo
{
  int i;
  double d;
};

以下两行之间有什么区别:

What are the differences between the following two lines:

Foo* f1 = new Foo;
Foo* f2 = new Foo();


推荐答案

第一个保留值未初始化;第二个将它们初始化为零。这只适用于没有构造函数的POD类型。

The first one leaves the values uninitialised; the second initialises them to zero. This is only the case for POD types, which have no constructors.

这篇关于C ++中的默认结构初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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