Using variable from main in class


How do you access a variable that has it's assignment in main accessible to other classes without passing the value as a parameter?

For example, if I want to assign a variable "listNumber" in the main program, e.g.:

int main(int argc, char** argv)
{
listNumber = 2;
}

and I have a class called in main that wanted to access that value for assembling an output file like "output_for_listNumber_2" where I would have

int num = access_main_for_listNumber;
std::stringstream convert;
convert << num;
std::string numS = convert.str();
std::string outputFile = "output_for_ListNumber_" + numS;


Normally, I would put something like:

"int GetListNumber() { return listNumber; };"

in a class header file.

and then use

someClass->GetListNumber();

but main doesn't have a header file....

Thanks in advance.


You would have a data member in side the class that you could assign the value to, it would have to be public, or you would have to have a member function that takes an argument from main and assigns the value to the data memeber in the class.
Topic archived. No new replies allowed.