Results 1 to 7 of 7

Thread: Handle to Parent Class

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Allen Park, MI, Wayne
    Posts
    39

    Handle to Parent Class

    Is there an easy way to get a handle to a parent class?

    class Class1{
    int m_y;
    int m_x;
    Class2 c2;

    }

    class Class2{
    //I'd like to talk back to class 1 and set some variables, or call some functions
    }

    I tried creating a whole class pointer, but that went down in flames.

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You could always make the members public, but it's better to encapsulate them.

    Anyway, read this, since you have a long OOP way to go

    http://newdata.box.sk/bx/c/

    good luck, and if you need concrete examples, you have to wait a day or 2 since I haven't have my VS installed yet.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Allen Park, MI, Wayne
    Posts
    39
    thanks for the link, I've read that and quite a few others. Just got out of a week long MFC course. I'm certified in desktop + distributed VB, I just dont get this dammmmmed pointer between class business.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    check your other thread, you just have to make a pointer to the other class

    oh and LTNS jop, haven't seen you around here for ages
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yeah keda really good to see you again my friend, glad to be back in bussiness
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Allen Park, MI, Wayne
    Posts
    39
    Thread? I didnt start any threads? Can you show me using the Class1, Class2 illustration how you would do that?

    Thx

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    class Class1;
    
    class Class2{
      // I'd like to talk back to class 1 and set
      // some variables, or call some functions
      Class1 &parent;
    public:
      Class2(Class1 &p) : parent(p) {};
    };
    
    class Class1{
      int m_y;
      int m_x;
      Class2 c2;
    public:
      Class1() : c2(*this) {};
    };
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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