Simple access to embedded class objects

Discussion in 'C++' started by PSN, Oct 16, 2006.

  1. PSN

    PSN Guest

    Hi all ,,
    I have a complex class which inturn contains several classses and
    subclasses .. can some one give me an easy method to access the deep
    most member variables (explained in the example below) .. However, i
    have a much complex class with asmany as 6-7 subclasses ...

    Please note that the names of the classes are completely different from
    one another .. so we cannot form a uniform struncture of their titles
    ...

    class C {
    public:
    class a1
    {
    public:
    class a11 {
    public:
    class aaaa {
    public:
    int a;
    int
    func_1(){return a;}
    ....
    };
    class bbbb {
    public:
    int b;
    int
    func_2(){return b;}
    ....
    };

    aaaa OBJaaaa;
    bbbb OBJaaaa;

    };

    class b11 {
    public:
    class cccc{
    public:
    int a;
    int
    func_3(){return a;}
    ....
    };
    class dddd{
    public:
    int b;
    int
    func_4(){return b;}
    ....
    };

    cccc OBJcccc;
    dddd OBJdddd;

    };

    a11 OBJaa;
    b11 OBJbb;
    }*ptrC;

    currently i use the following method which is highly laborious and
    error prone ..

    switch(ptrC->WhichObjectInitialized())
    {
    case 0:
    switch(ptrC->OBJaa.WhichObjectInitialized())
    {
    case 0:
    return ptrC->OBJaa.OBJaaaa.func_1();
    break;
    case 1:
    return ptrC->OBJaa.OBJbbbb.func_2();
    break;
    }
    break;
    case 1:
    switch(ptrC->OBJbb.WhichObjectInitialized())
    {
    case 0:
    return ptrC->OBJaa.OBJcccc.func_3();
    break;
    case 1:
    return ptrC->OBJaa.OBJdddd.func_4();
    break;
    }
    break;
    }

    any help is highly appriciated ..

    prakash
     
    PSN, Oct 16, 2006
    #1
    1. Advertising

  2. PSN wrote:
    > Hi all ,,
    > I have a complex class which inturn contains several classses and
    > subclasses .. can some one give me an easy method to access the deep
    > most member variables (explained in the example below) .. However, i
    > have a much complex class with asmany as 6-7 subclasses ...


    WHY??? Why couldn't you, say, have all those classes outside at the
    namespace level? And why do you keep all those members if they are
    not always used? Shouldn't they all be in a class hierarchy and then
    in a list/map/set of base class pointers? What is it you're trying to
    model here?

    > [..]


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 16, 2006
    #2
    1. Advertising

  3. PSN

    PSN Guest

    HI,
    thanks for your reply ..

    it is a complex structure representing, let me just put it as a
    communication protocol message (more specifically a MAC message) ..
    more over i have no access to alter this code, other than use a pointer
    to the object of the message ..

    so simply put, neither can i add any code nor can i create a new
    structure out of it .. just got to use this ..

    still any ideas ..

    Prakash
    Victor Bazarov wrote:
    > PSN wrote:
    > > Hi all ,,
    > > I have a complex class which inturn contains several classses and
    > > subclasses .. can some one give me an easy method to access the deep
    > > most member variables (explained in the example below) .. However, i
    > > have a much complex class with asmany as 6-7 subclasses ...

    >
    > WHY??? Why couldn't you, say, have all those classes outside at the
    > namespace level? And why do you keep all those members if they are
    > not always used? Shouldn't they all be in a class hierarchy and then
    > in a list/map/set of base class pointers? What is it you're trying to
    > model here?
    >
    > > [..]

    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask
     
    PSN, Oct 16, 2006
    #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. Colin Paul Gloster
    Replies:
    48
    Views:
    1,935
    Colin Paul Gloster
    Apr 10, 2007
  2. 7stud
    Replies:
    11
    Views:
    729
    Dennis Lee Bieber
    Mar 20, 2007
  3. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    420
    Thomas Dodds
    Jul 26, 2004
  4. Trans
    Replies:
    11
    Views:
    328
    micathom
    Sep 5, 2007
  5. Num GG
    Replies:
    2
    Views:
    394
    Num GG
    Nov 17, 2008
Loading...

Share This Page