0

I have static variable which is initialized before main. This static variable is initialized based on argv and argc.

However the main function is launched after static variable is instantiating so argv and argc are not available yet.

how can I do that? how can I know what are the flag values in order to init the static variable?

bochaltura
  • 257
  • 5
  • 14
  • 4
    That's correct. Did you have a question? – underscore_d Dec 11 '17 at 15:26
  • 1
    So it sounds like you have to actually initialize your static variable from within main instead. So do that, e.g. make a member function on your object that you can call to pass argc and argv, call that function from main. – nos Dec 11 '17 at 15:31
  • since `static` class members are just posh `static` objects, this is effectively a duplicate of [Can I initialize a static const member at run-time in C++?](https://stackoverflow.com/questions/33572283/can-i-initialize-a-static-const-member-at-run-time-in-c) – underscore_d Dec 11 '17 at 15:34

1 Answers1

0

[...]before argv parameter is processed by main
This static variable is initialized based on argv and argc.

Well... where is the problem ? Just initialize it before you actually process the data.

static int Count = 0;

int main(int argv, char **args)
{
    Count = argv; //Init
    //Process
}
Blacktempel
  • 3,935
  • 3
  • 29
  • 53