#include<iostream.h>
//main()
//{

class A
{
friend class B;
public:
void read();
};
class B
{
public :
int a,b;
};
void A::read()
{
cout<<"welcome";
}

main()
{
A x;
B y;
y.read();
}

In the above program......,
as B is a friend of A B can have access to all members,i
cant access y.read .
could you please tell me the reason and what would i code
to execute this program?

Answers were Sorted based on User's Feedback



#include<iostream.h> //main() //{ class A { friend class B; public: void read(); }; ..

Answer / manzoor

write a program to larger of two number by using friend
function in c++

Is This Answer Correct ?    5 Yes 0 No

#include<iostream.h> //main() //{ class A { friend class B; public: void read(); }; ..

Answer / nn

declare friend class b under public

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C++ Code Interview Questions

write a program that can locate elements in array.

1 Answers  


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

0 Answers   HCL, SRCASW,


i don't know about working of nested for loop can any one help me

0 Answers  


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

0 Answers  


void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else cout<<"Rose "; } Its result is Rose Lotus Lotus.. How? Explain it?

2 Answers  






Perform the functionality of 2-D array through 1-D array and in it the functions to be performed were: (1) Display the array in 2-D format (2) Display a particular element (3) Display a particular row (4) Display a particular column

1 Answers   Nagarro,


write a program to perform generic sort in arrays?

0 Answers  


how to diplay a external image of output on winxp by using c & c++,

0 Answers  


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

0 Answers  


How to Split Strings with Regex in Managed C++ Applications?

0 Answers   Microsoft,


Code for Two Classes for Doing Gzip in Memory?

0 Answers  


Subsets Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a list that is the input to the algorithm. (Since it is a set, you may assume all elements in the list are distinct.)

1 Answers   CSC, Qatar University,


Categories