数组的初始化 [英] Initialization of an array

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

问题描述

如何在

构造函数的初始化列表中初始化数组?


SomeClass

{

public:

SomeClass():* init here * {}

private:

int some_array [2] ;

};

How can you initialize an array, in the initialization list of a
constructor ??

SomeClass
{
public:
SomeClass() : *init here* { }
private:
int some_array[2];
};

推荐答案

jamx写道:
jamx wrote:

如何在

构造函数的初始化列表中初始化数组?


SomeClass

{

public:

SomeClass():* init here * {}

private:

int some_array [ 2];

};
How can you initialize an array, in the initialization list of a
constructor ??

SomeClass
{
public:
SomeClass() : *init here* { }
private:
int some_array[2];
};



你不能。


V

-

请在通过电子邮件回复时删除大写''A'

我没有回复最热门的回复,请不要问

You cannot.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask

jamx写道:
jamx wrote:

如何在

构造函数的初始化列表中初始化数组?


SomeClass

{

public:

SomeClass():* init here * {}

私人:

int some_array [2];

};
How can you initialize an array, in the initialization list of a
constructor ??

SomeClass
{
public:
SomeClass() : *init here* { }
private:
int some_array[2];
};



你不能直接做,但你可以使用这样的:


class Init

{

public:

Init(int(& array)[2])

{

array [0] = 42;

array [1] = 43;

}

};


class SomeClass:private Init

{

public:

SomeClass():Init(some_array){}

私人:

int some_array [2];

};


-

Salu2

You can''t do it directly, but you can use some like this:

class Init
{
public:
Init (int (& array ) [2])
{
array [0]= 42;
array [1]= 43;
}
};

class SomeClass : private Init
{
public:
SomeClass() : Init (some_array) { }
private:
int some_array[2];
};

--
Salu2


* Victor Bazarov:
* Victor Bazarov:

jamx写道:
jamx wrote:

>如何在
构造函数的初始化列表中初始化数组?

SomeClass
{
public :
SomeClass():* init here * {}
private:
int some_array [2];
};
>How can you initialize an array, in the initialization list of a
constructor ??

SomeClass
{
public:
SomeClass() : *init here* { }
private:
int some_array[2];
};



你不能。


You cannot.



嗯,你可以零初始化它。


-

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

问:为什么这么糟糕?

A:热门帖子。

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

Well, you can zero-initialize it.

--
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?


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

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