J
Juke All
When I compile the code (below), I get this error:
cannot convert parameter 1 from 'int' to 'union dna'
Without saying:
FOO x;
x.val = 100;
....is it possible to use a union as a function parameter, and when
calling that function, pass the argument as one of the types of the
union (int, in the following case)?
typedef union foo
{
void* ptr;
int val;
} FOO;
void* test(FOO obj)
{
void* ptr = obj.ptr;
int val = obj.val;
return NULL;
}
int main(int argc, char* argv[])
{
int x = 100;
test(x);
return 0;
}
cannot convert parameter 1 from 'int' to 'union dna'
Without saying:
FOO x;
x.val = 100;
....is it possible to use a union as a function parameter, and when
calling that function, pass the argument as one of the types of the
union (int, in the following case)?
typedef union foo
{
void* ptr;
int val;
} FOO;
void* test(FOO obj)
{
void* ptr = obj.ptr;
int val = obj.val;
return NULL;
}
int main(int argc, char* argv[])
{
int x = 100;
test(x);
return 0;
}