I have a debug assertion that fails when running Dinner.Init(Baskets,Bags);
The error message is vector subscript out of range.
I think it has something to do with the initialization of the variable sized arrays. It takes an unusually long time at the step Dinner(int num): Apple(num){ }.
Are the error message and delay related? Is there a solution for both?
In foo.h
#include <vector>
extern int num1
extern int num2
#define Baskets = num1+num2
#define Bags = num1*2
struct AppleStruct
{
std::vector<int> Chunks;
AppleStruct(){}
AppleStruct(int num):Chunks(num){ }
};
Class Dinner
{
std::vector<AppleStruct> Apple;
public:
Dinner(){}
Dinner(int num): Apple(num){ }
void Init(int num1, int num2);
}
void Dinner::Init(int num1, int num2)
{
int i, j;
for (i=0; i<num1; i++) // Fill everything INVALIDs
{
for (j=0; j<num2; j++)
{
Apple[i].Chunks[j]=1;
}
}
}
In foo.cpp
#include "foo.h"
int num1;
int num2;
int main(int argc, char *argv[])
{
sscanf_s(argv[1],"%d",&num1);
sscanf_s(argv[2],"%d",&num2);
AppleStruct(Bags);
Dinner(Baskets);
Dinner.Init(Baskets,Bags);
return 0;
}