This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
强调文本在main中声明的变量B
具有数组类型。数组没有成员功能。因此,此陈述
是不正确的。例如,您可以写作,
但是在成员函数集中,使用了调用
未定义行为的非直接指针
b
。因此,您的代码只是没有意义。
似乎您需要一个静态成员函数,例如
,
删除数据成员B和N。
在这种情况下,您应该在类定义中
可以按照以下方式声明和定义函数获取
,对于主要的声明数组,函数可以称为以下方式
emphasized textThe variable b declared in main
has an array type. Arrays do not have member functions. So this statement
is incorrect. You could write for example
However within the member function set there is used uninitialized pointer
b
that invokes undefined behavior.
So your code as is just does not make a sense.
It seems you need a static member function like for example
And call it like
In this case you should remove the data members b and n
in the class definition.
The function get can be declared and defined the following way
And for the declared array in main the function can be called the following way