identifying a structure in a class

ok let's say you have the following code
1
2
3
4
5
6
7
8
class someclass{
   public:
   struct somestruct{
    int a;
    int b;
  }structObj;
   void function(void){};
}classObj;


How do I specify the object structObj of classObj. Meaning if I wanted to specify function of classObj I would say classObj::function(). So how would I specify int a in structObj classObj
 
classObj.structObj.a = 1;
I apologize, what if these were pointers to objects rather than objects. Thank you for the quick reply.
Don't do this:
1
2
3
4
   struct somestruct{
    int a;
    int b;
  }structObj;
You're clearly confusing your self.

This shows the syntax for accessing the members of the nested struct:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class someclass
{
public:
    struct somestruct
    {
        int a;
        int b;
    };

    somestruct s;
    void somefunction();
};

void someclass::somefunction()
{
    s.a = 3;
    s.b = 4;
}

int function()
{
    someclass c;
    c.s.a = 1;
    c.s.b = 2;
}
In the case of pointers, just use regular pointer syntax:
1
2
3
4
5
6
7
8
//If someclass is a pointer:
someclass->somestruct.a;
//If somestruct is a pointer:
someclass.somestruct->a;
//If a is a pointer:
int b = *(someclass.somstruct.a);
//If they're all pointers:
int b = *(someclass->somestruct->a);
Thank you
Topic archived. No new replies allowed.