please see the snippet of my c++ code below. Because foo.h is executed before int main(int argc, char *argv[]), the array RedApple will be initialized with size 0 and causes an error. What is the best way to deal with this problem? Is there a way to keep the class declaration in foo.h, but initialize it in foo.cpp from the user input? Thanks!
In foo.h
#include <vector>
extern int num;
class apple
{
std::vector<long> RedApple;
public:
apple(): RedApple(num)
}
In foo.cpp
#include "foo.h"
int num;
int main(int argc, char *argv[])
{
sscanf_s(argv[1],"%d",&num);
}