error variable not declared
hi..
In .h file I have declared
Code:
union Uni1{
int a_data;
float b_data;
}UTemp
In .cpp I want to access the variables in the union i.e UTemp.a or UTemp.b;
But while compiling error is generated :
Quote:
error: a_data has not been declared.
error: a_data has not been declared.
Pls help
Re: error variable not declared
Your error must be related to any other thing.
I created the file test.h:
Code:
union Uni1{
int a_data;
float b_data;
}UTemp;
and the test.cpp:
Code:
#include "test.h"
int main(int, char**)
{
UTemp.a_data = 10;
UTemp.b_data = 3.5f;
return UTemp.a_data;
}
compiled through:
g++ test.cpp
There were no error complains and the a.out output file was correctly generated. You haven't forgot the ';' after UTemp declaration, have you?
Cheers