【发布时间】:2017-08-13 22:16:15
【问题描述】:
这是我在这里的第一个问题,我很兴奋!
我想从 Person 类创建很多对象,从字符串数组中获取每个对象的名称。
类似这样的:
class Person
{
// bla bla bla
};
string listOfPersons [5000];
// here i will fill in the whole array with names
for (int i=0;i<5000);i++){
// here: create the objects with the name from the array
// like Person Mary.... Person John... Person... Patricia...
}
非常感谢!!
【问题讨论】:
-
你的问题是现在?
-
我不明白这个问题。
-
嗨,Pablo,欢迎来到 StackOverflow。当您说“它不起作用”时,请更具描述性。如果可能的话,给出一个准确的错误信息,以及预期的输入和输出。此外,您可能希望从较小的人开始,可能是 1 人而不是 5k :-)
-
Person listOfPersons [i] //here is where it doesn't work 正确,由于多种原因会失败。 1. 您的 Person 数组必须在循环外声明。 2.不要和你的字符串数组一样命名。
-
create object是什么意思?如果您的意思是在运行时创建新类型,那么您不能。