20120113

How to use friend function in C++

//Program in cpp to demonstrate friend1.cpp
#include<iostream>
using namespace std;
class base;
class anyClass
{
private:
friend class base;
anyClass()
{}
};
class base
{
public:
        virtual anyClass *createanyClass()
        {
        return new anyClass;
        }
};
class derived:public base
{
public:
        anyClass *createanyClass()
        {
        //return new anyClass;// base is frnd of another doesnot mean derive                                   //
class also will be friend  access private
        }
};
int main()
{
base b;
derived d;
b.createanyClass();
return 0;
}
How to use friend function in Cpp/C++
How to use friend function in Cpp/C++
How to use friend function in Cpp/C++
How to use friend function in Cpp/C++

3 comments:

  1. How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    ReplyDelete
  2. How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp
    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp
    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp
    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    ReplyDelete
  3. How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp
    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp
    How to use friend function in C++
    Program in cpp to demonstrate friend1.cpp

    ReplyDelete