Reputation: 39
I was just starting writing a program, when I noticed something I do not understand. I have defined a structure called "time". When I try to define a structure variable called "time1", it send out an error: "expected an ';'". But when I remove the header file "iomanip" the error disappears! And when I include it again the error comes back. Why does this happen?
Upvotes: 0
Views: 4039
Reputation: 598
if you don't want to rename the name of struct, then you can change it to this:
#include <iomanip>
struct time
{
int a;
};
int main()
{
struct time t1;
}
Upvotes: 0
Reputation: 29986
Let's try out this piece of code:
#include <iomanip>
struct time
{
int a;
};
int main()
{
time t1;
}
Here's the error, and a warning that I'm getting in QtCreator when I try to compile this (mycompiler is g++ 4.6.3). The compiler thinks that time
here is not a statement, but a function name:
Apparently, <iomanip>
somehow includes <time.h>
, and time.h
has a function called time(). So, basicaly, just rename your structure to "myTime" or something like that.
Upvotes: 4