//Example1 calling member data of a friend class
#include<iostream>
using namespace std;
class A{
private:
int x;
public:
A(){
cout<<"constructor A\t"<<endl;
}
~A(){
cout<<"Destructor A\t"<<endl;
}
friend class B;
};
class B{
public:
B(){
cout<<"constructor B"<<endl;
}
~B(){
cout<<"Destructor B"<<endl;
}
void Func1(A&a)//passing object is preferred to be by address
{
cout<<"inside class B,please Enter value of x:\t"<<endl;
cin>>a.x;
cout<<"value of x is:\t"<<a.x<<endl;
}
};
#include<iostream>
#include "Friend classB.h"
int main(){
A a;
B b;
b.Func1(a);
system("pause");
return 0;
}
error is
\Users\go\Documents\examples of c++OOP\lec 8_friend member data.cpp C:\Users\go\Documents\examples of c++OOP\C Friend classB.h: No such file or directory.
**Mod Edit: Changed title to be more descriptive**
This post has been edited by OliveOyl3471: 31 January 2010 - 01:52 PM

New Topic/Question
Reply




MultiQuote






|