answersLogoWhite

0

What else can I help you with?

Related Questions

What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.


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


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 the friend function implications on information hiding?

Other than that the friend has privileged access to the private members of the class in which it is declared a friend, there are no implications. However, there has to a be a reason for the friend to require that access.


What are the limitations of friend function?

Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope.


What are the limitations of friend function in c plus plus?

Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope. At this data hiding feature of c++ is broken.


Does he like you as a friend?

well, if you basically talk in class or out of class he or she probably likes you as a friend. But if you joke around and play hit each other you are probably more than friends


I sit next to a boy in one class and we get along pretty well but how do I get him to notice me as more than a friend?

Try to tell him that you like him, or hang out with him more out of the class.


Why we make a function friend in c plus plus?

A "normal" function is just a function. Even a friend function is just a normal function. However, when a class declares an external function or an external class method to be a friend of the class, the friend function gains access to the private members of the class. class foo { friend void bar(foo&); int m_data; }; void bar(foo& f) { f.m_data=42; } In the example above, the foo class declares the bar function to be a friend function. As such, the bar function has unrestricted access to the private members of foo. In this case, foo::m_data is private (by default) and would therefore be inaccessible to bar were it not declared a friend of foo. Other than that, the bar function is no different to any other function. Note that you cannot declare friendship from outside of a class. The class itself must declare its own friends. However, the same function can be declared friends in more than one class, which can be a useful feature when two or more classes work closely together, as the friend function can be used to provide the "glue" that binds them together.


How does friend operator function differ from member operator function?

In C++, we know that private members cannot be accessed from the outside class.That is a non-member function cannot have an access to the private data of a class.However there could be a situation where we would like two classes to share a particular function.For example consider a case where two classes, manager and scientist have been defined.We would like to use a function income_ tax () to operate on the objects of both these classes.In such situation, C++ allows the common function to be made friendly with both the classes. Such a function needs not be member of any these classes.To make outside function friendly to a class, we have to simply declare this function as a friend of a class as shown below:Class ABC{………..Public:……..……..Friend void xyz (void); //declaration};When the function is logically coupled with the class (like your maze connectedness example)When the function needs to access private or protected members, it's better to make it a member than a friend. when it's a generic function that can be templatized to naturally work on other classes (look at the header for good example) .


Disadvantages of friend function in c plus plus?

C is not object oriented programming language thus there are no friend functions in C. In C++, which is object oriented, the advantage of a friend is that it allows code that cannot otherwise be regarded as being a member of the class to gain private access to the class representation, where public access to the representation would be considered undesirable. Although many see friendship as an undermining of encapsulation, the reality is it strengthens encapsulation by limiting exposure to the representation to only those functions that actually require that access. Public access is fully accessible, of course, but is not always desirable. Interfaces must be kept as simple as possible, but exposing an interface that is only of use to a few non-member functions is less desirable than simply making those functions friends of the class. It is important to understand the relationships between functions and classes. All functions can be divided into one of three distinct categories with respect to any one class: non-member functions; static member functions or; nonstatic member functions. Nonstatic member functions of a class have all three of the following properties: 1. The function has private access to the class representation. 2. The function is scoped to the class. 3. The function must be invoked upon an object of the class (has a 'this' pointer). Static member functions only have the first two properties while friend functions only have the first property. External (non-friend) functions do not have any of these properties. The only disadvantage to a friend function is when that friend is outwith the control of the class designer. Since friends have private access they must obey the class invariants, just as any member of the class must. Although they are not members of the class per se, they must be implemented just as if they were. In other words, they must not invalidate the representation. When the class designer has full control over the friends of that class then this is not a major problem. But when third-party programmers have access to the friend implementations, encapsulation can no longer be guaranteed by the class designer -- it is seriously undermined. But when used appropriately, friends actively re-enforce encapsulation and are no more an undermining of encapsulation than is public inheritance.


How friend function in c plus plus created?

Within a class declaration, include the following:friend ;For example:friend class MyClass; // friend classfriend void MyClass::SomeFunction(); // friend class method.friend void MyFunction(); // friend function.When declaring friend functions and friend class methods, you must declare an unambiguous prototype, including its return type and its parameter types, and all instances of the const keyword. If the function prototype is contained in another file, that file must also be included in the class declaration file.Friends can be declared anywhere in a class declaration. However, friends cannot be inherited so it doesn't matter if they're declared public, private or protected (access specifiers have no meaning to friends). But be aware that friends have privileged access to all members, including private and protected members. This is said to undermine the fundamentals of encapsulation, however the purpose of a friend is to extend the class interface, and is no more an undermining of encapsulation than is public inheritance. However, access should be limited to as few friends as possible; a class with many friends implies a fundamental design flaw in the class.