默认构造函数初始化值? [英] does the default constructor initialize values?

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

问题描述

默认构造函数是否初始化值?


我有一个如下定义的类:


class A

{


int i;

char c;

int * iPtr;


};

默认构造函数是否初始化i,c&的值。 iPtr?


如果是这样,他们每个人初始化的价值是什么?


谢谢。

does the default constructor initialize values?

I have a class as defined below:

class A
{

int i;
char c;
int * iPtr;

};
Does the default constructor initialize the values of i, c & iPtr?

If so, what are the values that they each get initialized to?

thanks.

推荐答案



NewToCPP写道:

NewToCPP wrote:

默认构造函数初始化值?


我有一个课程定义如下:


A级

{


int i;

char c;

int * iPtr;


};


默认构造函数是否初始化i,c&的值。 iPtr?


如果是这样,它们每个初始化的值是多少?
does the default constructor initialize values?

I have a class as defined below:

class A
{

int i;
char c;
int * iPtr;

};
Does the default constructor initialize the values of i, c & iPtr?

If so, what are the values that they each get initialized to?



零初始化它们。

It zero initializes them.


>

谢谢。
>
thanks.


* Noah Roberts:
* Noah Roberts:

NewToCPP写道:
NewToCPP wrote:

>默认构造函数是否初始化值?

我有一个如下定义的类:

A类
{

int i;
char c;
int * iPtr;

};

默认构造函数是否初始化值我,c& iPtr?

如果是这样,他们每个人初始化的价值是什么?
>does the default constructor initialize values?

I have a class as defined below:

class A
{

int i;
char c;
int * iPtr;

};
Does the default constructor initialize the values of i, c & iPtr?

If so, what are the values that they each get initialized to?



零初始化它们。


It zero initializes them.



不,它完全没有(在这个类中)。


int main()

{

A o; //默认构造,o的成员未初始化。

}


-

答:因为它搞砸了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

Q :usenet和电子邮件中最烦人的事情是什么?

No, it does exactly nothing (in this class).

int main()
{
A o; // Default-constructed, members of o are not initialized.
}

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


NewToCPP写道:
NewToCPP wrote:

默认构造函数初始化值?
does the default constructor initialize values?



这取决于。

That depends.


我有一个如下定义的课程:

A级

{


int i;

char c;

int * iPtr;


};
I have a class as defined below:

class A
{

int i;
char c;
int * iPtr;

};



注意这个类是没用的,因为所有成员都是私有的。

Note that this class is quite useless, because all the members are private.


是否默认构造函数初始化i,c&的值。 IPTR?
Does the default constructor initialize the values of i, c & iPtr?



在这种情况下,编译器将生成默认构造函数。它没有做什么,所以不,这些价值不会被初始化。

In this case, the default constructor will be generated by the compiler. It
does nothing, so no, the values won''t get initialized.


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

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