Hi all,
I would like to use the tm struct as a static variable.
The date to store would not be the current system time but one manually entered during runtime.
In my class, under Public, i have declared it as:
static struct tm *dataTime;
In the main.cpp, I have tried to define and initialize it with system time temporarily to test out
time_t rawTime;
time ( &rawTime );
tm Indice::dataTime = localtime(&rawTime);
but seems like i can't use time() outside functions.
main.cpp:28: error: expected constructor, destructor, or type conversion before ‘(’ token
How do I initialize values in a static tm of a class?
Last edited on
It works now! Thanks
But I ran into another problem which is to write values into the tm struct
I thought accessing via
Indice::dataTime->tm_year
should be right but got the error
parser.h:121: error: base operand of ‘->’ has non-pointer type ‘tm’
>.< Is the problem lying somewhere else or that using -> to access structs is wrong
tm is not a pointer. It is a struct. Try Indice::dateTime.tm_year.