accessing inner struct members

Discussion in 'C++' started by Walter Deodiaus, Dec 29, 2005.

  1. I have
    typedef struct {
    union _union{
    ....
    struct {
    int i;
    }u1;
    ....
    }Union;
    } Struct ;


    now I want to define a method's signaure whose first arg will be "u1"

    e.g. foo(Struct::Union.u1)

    Is this possible without changing the layout to
    struct _u1{
    int b;
    } ;
    typedef struct {
    union _union{
    ....
    _u1 u1;
    ....
    }Union;
    } Struct ;

    method's signature
    foo(u1 the_u1);
     
    Walter Deodiaus, Dec 29, 2005
    #1
    1. Advertising

  2. Walter Deodiaus

    mlimber Guest

    Walter Deodiaus wrote:
    > I have
    > typedef struct {
    > union _union{
    > ...
    > struct {
    > int i;
    > }u1;
    > ...
    > }Union;
    > } Struct ;
    >
    >
    > now I want to define a method's signaure whose first arg will be "u1"
    >
    > e.g. foo(Struct::Union.u1)
    >
    > Is this possible without changing the layout to
    > struct _u1{
    > int b;
    > } ;
    > typedef struct {
    > union _union{
    > ...
    > _u1 u1;
    > ...
    > }Union;
    > } Struct ;
    >
    > method's signature
    > foo(u1 the_u1);


    You want something like:

    struct S1
    {
    union U
    {
    char c[4];
    struct S2
    {
    int i;
    } s2;
    } u;
    };

    void foo(S1::U::S2);

    int main()
    {
    foo( S1::U::S2() );
    }

    Cheers! --M
     
    mlimber, Dec 29, 2005
    #2
    1. Advertising

  3. Walter Deodiaus

    Old Wolf Guest

    Walter Deodiaus wrote:

    > struct {
    > int i;
    > }u1;
    >
    > now I want to define a method's signaure whose first arg will be "u1"


    You didn't give the struct a type name, so it is impossible to
    refer to its type.
     
    Old Wolf, Dec 29, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Accessing members of a struct

    , Apr 11, 2006, in forum: C Programming
    Replies:
    5
    Views:
    296
    Barry Schwarz
    Apr 13, 2006
  2. Replies:
    3
    Views:
    313
  3. Mark Shelor

    Accessing C struct members via T_PTROBJ

    Mark Shelor, Oct 24, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    144
    Tassilo v. Parseval
    Oct 25, 2003
  4. John Reye
    Replies:
    28
    Views:
    1,412
    Tim Rentsch
    May 8, 2012
  5. Mark
    Replies:
    6
    Views:
    405
    88888 Dihedral
    Jul 9, 2012
Loading...

Share This Page