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

Thread: Friend function

Threaded View

  1. #1
    Join Date
    May 2007
    Posts
    85

    Friend function

    Hello,
    Consider this scenario,
    Code:
    class B;
    class A
    {
        private:
              int x, y;
        public:
              A(){}
        friend void func( A a, B b );
    };
    
    class B
    {
        private:
              int i, j;
        public:
              B(){}
        friend void func( A a, B b );
    };
    Friend function is used to allow non-members to access private data defined inside a class. Now my question is I have two variables x and y in class A, and two variables i and j in class B. Is it possible that I can allow my users (outside class) to access only variable x and not y defined in class A ? Similarly, allow access outside class only to variable i and not to j in class B.
    NOTE: The above scenario should happen only when friend is defined.

    Thanks
    Last edited by Jacko123; August 20th, 2007 at 05:01 AM.

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