Click to See Complete Forum and Search --> : members of parent object


unmanarc
December 13th, 2002, 08:43 PM
how can i access the members of parent object?...

ex.

class Cparent
{
public:
int a;
void funtionX();
}

class Cchild
{
public:
void funtionY();
}


void Cparent::functionX()
{
a=0;
Cchild chd;
chd.functionY();
}

void Cchild::functionY()
{
// how can i access "a" from HERE without parse any data
}

NOTE 1: the code may contain errors, but i only want the method for access
NOTE 2: the two classes are separated in two files .cpp files.

galathaea
December 13th, 2002, 09:23 PM
I only see two classes with no relationship except that one of their methods instantiates the other one and calls the other one's methods. Then, I would see no reason why you couldn't just pass that data as a parameter in the call...

Maybe I am missing your intent? If you update your example to something closer to what you intend, I am sure one of us could help here, but as is, I say just pass it in the function call.

unmanarc
December 13th, 2002, 10:15 PM
ok, the real problem is that is not 1 or 2 parameters to parse...
is really about 30 functions, with more than 40 variables (10 or 15 need to be parsed), and data is changed on functions, etc.

the idea is create "globals" for all objects of the same program.

one idea is parse data as struct, but, then, when i modify data that are into struct, it does not modify the data of parent object.

NOTE: Im translating a big proyect (about 4000 lines) writed in C, to C++ object oriented. thats the real problem

i see something about "static members", but im not sure what is. has any relation?

the other posibility is use any class declared on "parent" class, but, how can i write this new sub-class in the 2nd file? (the reason for translate to C++ is divide the code in various fragments and not have 3500~4000 lines in one BIG .cpp)

thanks

TheCPUWizard
December 14th, 2002, 09:44 AM
One decent method of implementing globals (if you MUST is to create either a singleton or a static object (use a namespace if your compiler supports it).

Saurabh Gupta
December 17th, 2002, 01:01 AM
You can make variable a as global .
And make extern in to another file. Otherwise it will give error. But why you want such type of thing. Because variable a is a local variable of Cparent::functionX. So you can not
access it in to function Cchild::functionY stack.