PDA

View Full Version : error variable not declared



aj2903
3rd December 2008, 15:30
hi..
In .h file I have declared

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 :


error: a_data has not been declared.

error: a_data has not been declared.

Pls help

tinsuke
3rd December 2008, 16:58
Your error must be related to any other thing.
I created the file test.h:

union Uni1{
int a_data;
float b_data;
}UTemp;

and the test.cpp:

#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