我创建了一个程序,用于从文件中读取数据并从中创建对象。然而,它们的值可能会有所不同,因此我创建了一个可以扩展到一定数量的数组。当我尝试通过构造函数传递时遇到了一些麻烦。此外,我不应该使用从我理解会使这容易很多的载体。如何将数组中的值传递给构造函数? C++
//bunch of code to read in data from the file similar to this below
getline (readfile, typea);
//code determining what each data type is.
readMedia >>NSA_Value;
for (int i=0; i<=NSA_Value; i++){
getline(readMedia, supporting_actorsa[i]); //this is the array I'm using that can grow a bit to accommodate.
Vhs initial = Vhs(typea, a, b, c, supporting_actorsa[10]); //the constructor ive removed most of the other things to make it more readable.
这是它调用上创建对象
#include "Vhs.cpp"
Vhs::Vhs (string type, string a1, string b1, string c1, supporting_actorsa1[10])
{
}
Vhs::Vhs(void)
{
}
Vhs::~Vhs(void)
{
}
cpp文件,这这这是.h文件中
#pragma once
class Vhs
{
public:
Vhs(void);
Vhs (string type, string A2, string B2, string C3, string supporting_actorsA3[10]);
~Vhs(void);
};
所有的变量存在,我只是删除所有声明让事情看起来更干净。 感谢您的帮助
*“当我试图通过我碰到一些麻烦的构造函数来表示通过” * - 定义“麻烦”。细节很重要。 –
为什么你不能使用矢量?这会让整个情况变得微不足道:) – dreamlax
在那里有一个问题,我知道这是一个问题,但是它可能无法解决我的问题。 –