在课堂上的数组 [英] array in class

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

问题描述



我在一个课程中有一个数组,用以下方式判断:


char pippo [256];


在类的构造函数中我想填充这个数组,但是我收到了一个错误。

为什么?

tnx

解决方案

Salvatore Di Fazio写道:


我在一个类中以下列方式对一个数组进行了判断:


char pippo [256];


在构造函数中我要填写这个数组的类,但是我收到了一个错误。

为什么?



最有可能,因为你写了一些不正确的代码。


-

Salu2




Salvatore Di Fazio写道:




我在一个课程中按照以下方式排列了一个数组:


char pippo [256];


该类的构造函数我想填充这个数组,但是我收到了一个错误。

为什么?

tnx



错误在第42行。


好吧,这是你做的一种方式....

class Foo

{

私人:

char pippo [256];

public:

Foo();

};

void main()

{

Foo A;

}

Foo :: Foo()

{

//构造函数在main中声明对象时调用,并且

用于初始化私有成员变量你班上的e

for(int i = 0;皮波[I]; i ++)

{pippo [i] =''0''; }

}


- 您可能希望在程序的主要部分编写更多代码

来填充填充 ;数组。这个程序只用0'填充它。希望

有帮助!

Salvatore Di Fazio写道:




我在一个类中以下列方式对一个数组进行了判断:


char pippo [256];


在构造函数中我要填写这个数组的课程,但我收到了一个错误。

为什么?

tnx

Hi,
I''ve an array in a class declered in the following way:

char pippo[256];

In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx

解决方案

Salvatore Di Fazio wrote:

I''ve an array in a class declered in the following way:

char pippo[256];

In the constructor of the class I would like to fill this array, but I
received an error.
Why?

Most likely, because you write some incorrect code.

--
Salu2



Salvatore Di Fazio wrote:

Hi,
I''ve an array in a class declered in the following way:

char pippo[256];

In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx

The error is on line 42.


well, here is one way you do it....
class Foo
{
private:
char pippo[256];
public:
Foo();
};
void main()
{
Foo A;
}
Foo::Foo()
{
//constructor is called when you declared the object in main and is
usued to initalize private member variable in your class
for(int i = 0; pippo[i]; i++)
{ pippo[i] = ''0''; }
}

--You might want to write more code in the main portion of your program
to "fill" the array. This program only fills it with 0''s. Hope that
helps!
Salvatore Di Fazio wrote:

Hi,
I''ve an array in a class declered in the following way:

char pippo[256];

In the constructor of the class I would like to fill this array, but I
received an error.
Why?
tnx


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

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