CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    6

    changing values for one class and showing it ..!

    hi all,

    this is a pure c++ class problem , i am not good with pointers and it seems somehow pointers should be used,...pls see the problem below..

    i have three classes named super ,child1 and child2..

    #include "child1.h"
    #include "child2.h"

    class super
    {
    private:
    int record_clicks;
    ..
    child1 *myChild1;
    child2 *myChild2;
    ..
    };
    class child1
    {
    ..
    private:
    int record_clicks;
    ..
    }
    class child2
    {
    ..
    private:
    int record_clicks;
    ..
    }
    the problem i am facing is that that when i change the value in child1->recordClick i wanted to see the changed value in child2->recordClick, i make a function for that which passes the value of recordClick to TrainingUI which then passes this value to child2,but now if i wanted to change the value in child2->recordClick and show it on child1->recordClick ...how can i do that i mean how to change recordClicks value in both direction..i hope u undertsand

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: changing values for one class and showing it ..!

    I'm afraid your question does not make sense to me. It could be that you lack basic understanding of the programming concepts you are trying to use.
    I think there is a good chance other people will not understand this question either so you may get a quicker answer if you clarify.

    Regards / Z
    Nobody cares how it works as long as it works

  3. #3
    Join Date
    Aug 2007
    Posts
    858

    Re: changing values for one class and showing it ..!

    If I'm understanding you right... something like this is about the best you can do:

    Code:
    class super
    {
      int record_clicks;
      
      child1* myChild1;
      child2* myChild2;
      
    public:
      void SetClicks(int clicks)
      {
        record_clicks = clicks;
        myChild1->SetClicks(clicks);
        myChild2->SetClicks(clicks);
      }
    };
    
    class child1
    {
      int record_clicks;
      
    public:
      void SetClicks(int clicks) { record_clicks = clicks; }
    };
    
    //same for child2
    Although there's likely a better solution depending on exactly what it is you're trying to accomplish.

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