Reputation: 9
I have a main.h file and include static const unsigned int TIME = 13;
and i have and main.cpp file include
int64_t Gettime(int nnow, int64_t never)
{
static const bool TIME = true;
if(nnow == 6)
{
TIME = 9;
}
else if(nnow == 8)
{
TIME = 3;
}
else if(nnow == 1)
{
TIME = 40;
}
else if(nnow > 190)
{
TIME = 4000000;
}
return TIME + never;
}
on compile i get main.cpp:56:24: error: assignment of read-only variable ‘TIME’ TIME = 3; ^
i want to change the TIME variable from main.h using a main.cpp function any help ?
Upvotes: 0
Views: 5396
Reputation: 573
@shafeen answer is correct, but since it seems you aren't quite understanding it, how about some code?
Change this:
static const bool TIME = true;
To:
static bool TIME = true;
I would have put this as a comment to @shafeen's answer, but I don't have rep :(
Upvotes: 0
Reputation: 2457
The TIME
variable is declared a const
, so you will only be able to read its value but not modify it, that is what the compiler is letting you know in the error.
If you HAVE to modify that variable then you have to remove the const
qualifier.
Upvotes: 1