CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Need help!

  1. #1
    Guest

    Need help!

    I'm kinda new to the Object Orientated style of programming, I have a question that may seem a little silly to most. If I have to classes A and B, and in one of A's member functions I want to call one of B's member functions, how do I do it without using inheritance???
    Any help appreciated!!!



  2. #2
    Guest

    Re: Need help!

    Declare an object of B in the A's member function where U want to call it, then call it. Simple!!
    E.g.
    ClassAFunct() {
    ClassB ObjectB;
    ObjectB.ClassBFunct();
    }


  3. #3
    Guest

    Re: Need help!

    Not really that simple, 'coz B's constructor has several parameters for which I won't have values :-( Any other Ideas?


  4. #4
    Guest

    Re: Need help!

    Is it not possible for U to have another constructor just for this purpose?.
    May be it will just initialize everything to 0 or something......
    Later U can modify these values.
    Does it become too shabby?.




  5. #5
    Guest

    Re: Need help!

    Use external variables between the two classes in order to have values for your parameters. This is not a good method but it should get the job done.


  6. #6
    Guest

    Re: Need help!

    your can use friend class to do it .

    eg.
    class a
    {
    friend class b;
    functionA();
    }

    b::fuctionB()
    {
    fuctionA();
    }


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