Simple access to embedded class objects

P

PSN

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
 
V

Victor Bazarov

PSN said:
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
 
P

PSN

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 said:
PSN said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top