answersLogoWhite

0


Best Answer

disadvantage of friend functions is that they require an extra line

of code when you want dynamic binding. To get the effect of a virtual friend,

the friend function should call a hidden (usually protected:) virtual[20]

member function.

Read more: Demerits_of_friend_function

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

a

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the merit and demerit of using friend function in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the merits and demerits of using friend function?

disadvantage of friend functions is that they require an extra line of code when you want dynamic binding. To get the effect of a virtual friend, the friend function should call a hidden (usually protected:) virtual[20] member function.


How do you call a member function of one class in another class using friend function?

class B; // forward declaration. class A { private: void myFunction(B b){b.myFunction();} // Calls private method in b. }; class B { friend void A::myFunction(B b); // Friend function declaration. private: void MyFunction(); };


Why a friend function cannot be used to overload the assignment operator?

Assignment(=) operator is a special operator that will be provided by the constructor to the class when programmer has not provided(overloaded) as member of the class.(like copy constructor). When programmer is overloading = operator using friend function, two = operations will exists: 1) compiler is providing = operator 2) programmer is providing(overloading) = operator by friend function. Then simply ambiguity will be created and compiler will gives error. Its compilation error.


Can somebody give me the program to find simple interest using friend function in c plus plus?

Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.


How do you accept a string by using getch() function with an example?

explain about function call

Related questions

What are the Merits and Demerits of using HTML?

The merit of HTML is it's simplicity. The demerit is the lack of conditional statements.


What is the demerit of English language in India?

The English language is one of the two national languages of India. There is no demerit using the English language in India.


What are the merits and demerits of using friend function?

disadvantage of friend functions is that they require an extra line of code when you want dynamic binding. To get the effect of a virtual friend, the friend function should call a hidden (usually protected:) virtual[20] member function.


What are Merit and demerit of communicative approach?

The Communicative Approach is the focus on other activities in which a student learns a second language other than just using traditional teaching measures like proper grammar. It focuses on interaction with natives of that language to gain skill in proper pronunciation and understanding.


What are the merits and demerits of using function in c?

disadvantage of friend functions is that they require an extra lineof code when you want dynamic binding. To get the effect of a virtual friend,the friend function should call a hidden (usually protected:) virtual[20]member function.Read more: Demerits_of_friend_function


How do you call a member function of one class in another class using friend function?

class B; // forward declaration. class A { private: void myFunction(B b){b.myFunction();} // Calls private method in b. }; class B { friend void A::myFunction(B b); // Friend function declaration. private: void MyFunction(); };


Explain the advantages and disadvantages of friend functions?

by: THE DJ AKwww.the-dj-ak.webs.comwww.thedjak.co.nrwww.thedjak.webs.comWhat is a Friend Function?A friend function is a special function in c++ which inspite of not being member fuctionof a class has privalage to access private and protected data of a class.A friend function is a non member function of a class, that is declared as a friend usingthe keyword "friend" inside the class. By declaring a function as a friend, all the accesspermissions are given to the function.A friend function is used for accessing the non-public members of a class.A class can allow non-member functions and other classes to access its ownprivate data, by making them friends. Thus, a friend function is an ordinaryfunction or a member of another class.Need for Friend Function:As discussed in the earlier sections on access specifiers, when a datais declared as private inside a class, then it is not accessible from outsidethe class. A function that is not a member or an external class will notbe able to access the private data. A programmer may have a situation wherehe or she would need to access private data from non-member functions andexternal classes. For handling such cases, the concept of Friend functionsis a useful tool.How to define and use Friend Function in C++:The friend function is written as any other normal function, exceptthe function declaration of these functions is preceded with the keywordfriend. The friend function must have the class to which it is declared asfriend passed to it in argument.Some important points to note while using friend functions in C++:* The keyword friend is placed only in the function declaration of the friendfunction and not in the function definition..* It is possible to declare a function as friend in any number of classes..* When a class is declared as a friend, the friend class has access to theprivate data of the class that made this a friend..* A friend function, even though it is not a member function, would have therights to access the private members of the class..* It is possible to declare the friend function as either private or public..* The function can be invoked without the use of an object. The friend functionhas its argument as objects, seen in example below.properties of friend function:1. if a function to be made friend of a class than it should be declared within bodyof the class priciding with keyword friend.2.freind function never breaks the security.3.it should not be defined in name of class nor scope resolution operator is used in it'sdefination even the keyword freind is also not used while defining friend function.4.when friend function is called nither name of object nor dot operator is used. howeverit may accept the object as argument who's value it want's to access.5.it doen't matter in which section of the class we have declared a freind function.Example to understand the friend function:#includeclass exforsys{private:int a,b;public:void test(){a=100;b=200;}friend int compute(exforsys e1)//Friend Function Declaration with keyword friend and with the object of class exforsys to which it is friend passedto it};int compute(exforsys e1){//Friend Function Definition which has access to private datareturn int(e1.a+e2.b)-5;}main(){exforsys e;e.test();cout


Why a friend function cannot be used to overload the assignment operator?

Assignment(=) operator is a special operator that will be provided by the constructor to the class when programmer has not provided(overloaded) as member of the class.(like copy constructor). When programmer is overloading = operator using friend function, two = operations will exists: 1) compiler is providing = operator 2) programmer is providing(overloading) = operator by friend function. Then simply ambiguity will be created and compiler will gives error. Its compilation error.


What are merits and demerits of using Facebook?

Merits: Facebook is a powerful platform for connecting with others, sharing information, and promoting businesses. It allows users to stay in touch with friends and family regardless of distance. Demerits: Privacy concerns, spread of misinformation, and addiction are some of the potential drawbacks of using Facebook. The platform has also faced criticism for its impact on mental health and its role in spreading fake news.


Can somebody give me the program to find simple interest using friend function in c plus plus?

Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.


What can you do if your friend is using heroin?

tell that friend to stop using that


How it function using television set?

how it function using television set