我已经写了一个结构体和类,我想知道如何使用从文本文件中读取的值来调整它们的大小。这里是结构和类:如何调整结构或类成员的矢量大小?
typedef struct Chrom // creating the chrom structure
{
vector<vector <short int> > bit;
vector<vector <short int> > WaitingTime; //this is wij in the model
vector<vector <short int> > WaitingJob;//this is wj in the model, sigma wij must be equal to wj for each job J.
vector<vector <short int> > StartTime;
short int FinishTime;// finish time of each job in each machine
int fit;
} chrom;
在程序中,我读了一个数字是m。 但在程序中当我尝试使用chrom.ShortTime.resize(m)
。它给了我一个错误。即使我试图写这样的类:
class ProblemConstraint{
short int Jobs, Machines;
public:
vector <short int> Processing;
vector <short int> t1;
vector <short int> t2;
short int M;
short int W;
void set_values(int, int);
void resize(){
ProblemConstraint.Processing.resize(Machines);
}
}ProblemConstraint;
但我不能调整类中的向量的大小。有关如何在程序中的类或结构中调整矢量大小的任何建议?
你什么错误? – NathanOliver
“typedef struct Chrom” - 你不需要在C++中使用'typedef',这是一个C-ISM。 –
可能的重复 - https://stackoverflow.com/questions/37229215/how-to-resize-a-2d-vector-of-struct – JazzSoft