answersLogoWhite

0


Best Answer

We can access a Friend function from any other class in which friend function is introduced or declared even if the other class is not a member of first class.

But when we use normal member function, we can have its access only in the derived classes of the first class.

This is the basic difference between a friend function and a normal member function.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between friend function and normal member function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


What is the difference between strangers and friends?

A friend is a family member that you have chosen and a stranger is a friend that you have not met yet.


What is the difference between friend function and inheritance in c plus plus?

There is no such thing. When declaring a friend function only the explicitly-scoped friend is granted private access. The friend function may well be declared virtual within its own class but none of its overrides are granted access unless they are explicitly granted access.


Difference friend and public access modifier?

In C++, a friend function or friend class can grant access to its private data members to other classes. The public member allows any class to access that data.


Difference between member function and friend function?

1. Function - is normally refered to a C-style function which has a global level scope. As long as its declaration is visible in a file where it is being used, and the definition is available somewhere in the application, the linker will find the definition and link to it. It can be used anywhere in the application. 2. Member function - is normally referred to a C++Style method declared/defined inside of a C++ class. The scope for such member functions is the class. They are not accessible outside the class and are only accessible thru an object/instance of such a class. There are, of course, exceptions to this, such as static and friends.


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.


Is it possible to restrict a friend class's access to the private data member?

No. De-friend the friend class and provide an access method function.


Why friend are used in object oriented programing?

A friend function is a function that cannot be declared a member of a class but which requires private access to that class. For example, a function that operates upon two different classes cannot be a member of both classes, but if the function requires private access to both classes then it has to be a friend to at least one of them.To fully appreciate friend functions, consider that a non-static member function has the following three properties:Has private access to the class.Is scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. All other non-member functions have none of these properties.


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


How would you access data members of a class in cases inside member function of another class?

Either make the data members public, or make the member function a friend of the class containing the data member.


What is the difference between 'alsjeblieft' and 'alstublieft'?

Both 'alsjeblieft' and 'alstublieft' are Dutch words for "please." The main difference is in formality: 'alsjeblieft' is more casual and used among friends and family, while 'alstublieft' is more formal and used in professional or polite situations.


What is the difference between function and method in c language?

In object-oriented languages, a class member function is also known as a method. C does not provide native support for the object-oriented paradigm and therefore does not support methods.