CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Location
    venezuela
    Posts
    18

    members of parent object

    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.
    *-Unmanarc

  2. #2
    Join Date
    Sep 2002
    Posts
    1,747

    Parent? Child?

    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.
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  3. #3
    Join Date
    Dec 2002
    Location
    venezuela
    Posts
    18
    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
    Last edited by unmanarc; December 14th, 2002 at 10:45 AM.
    *-Unmanarc

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    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).
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Apr 2002
    Location
    India
    Posts
    26
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured