本文介绍了我试图插入并显示类类型数组中的值可以有人让我说对了吗?谢谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
using namespace std;
Class one
{
	public:
	string first;
	string second;
	int previousValue;
	int nextValue;
	void getData();
	void setData();
};
class two
{
	public:
	one array[10];
	void loadRecord();
};
int main()
{
	two ins;
	return 0;
}
two::loadRecord()
{
	for(int i=0;i<10;i++)
	{
		array[i]=//doesnot take input
	}
	for(int i=0;i<10;i++)
	{
		cout<<array[i]<<endl;//doesnot give output
	}

}





我尝试了什么:



上面的代码我试过但它没有给出输出



What I have tried:

the code above i have tried but it didnt give the output

推荐答案

two ins;



..你创建一个实例 ins 你的班级两个。这就是你的程序在它终止之前所做的全部。



你需要在它上面实际调用 loadRecord()



在这一行:


..you create an instance "ins" of your class two. And that's all your program does before it terminates.

You need to actually call loadRecord() on it.

And on this line:

array[i]=



..看起来你想要为你的班级分配一个新实例一个单个数组索引,但已经有(未初始化的)实例。



还有更多问题,但我建议你先解决这些问题。



我建议你为你的班级,班级成员和实际意味着什么的地方变量使用名称。一旦你的程序变得更大,one,two,ins,array就会变得非常混乱。


..it looks like you want to assign a new instance of your class one to the individual array indices but there already are (uninitialized) instances.

There are more issues but I suggest you start with fixing these.

I would recommend you to use names for your classes, class members and local variables that actually mean something. "one", "two", "ins", "array" will get pretty confusing once your programs get a bit larger.



这篇关于我试图插入并显示类类型数组中的值可以有人让我说对了吗?谢谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:32