![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
amahmoo
I am programming in c
Right. Did your instructor really tell you to do:
Code:
#include <iostream>
using namespace std;
We may have told you before, but that's a C++ header and the using directive is C++ syntax.
![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
amahmoo
look i didn't mean what you think doesn't matter. What you say does matter. I am sorry i didn't mean to sound that way also its my fault i am not clear in what i am asking is becase i dont understand what i am supposed to do.
Fair enough. Well, start by indenting your code properly:
Code:
#include <iostream>
using namespace std;
typedef struct
{
int a;
} struct_ex;
typedef struct example_1
{
union
{
struct_ex object_ex;
} test1;
} ex_1;
int main()
{
ex_1 ex_obj;
struct_ex *z = &ex_obj->test1.object_ex;
z->a = 1;
}
Now, it is easy to see that ex_obj is an ex_1 object. Therefore, it has a member named test1, which you should access as ex_obj.test1. ex_obj.test1 is a union with only one member, named object_ex. Therefore, you should access this member as ex_obj.test1.object_ex. So, if you want a pointer to this object:
Code:
struct_ex *z = &ex_obj.test1.object_ex;