GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 24 of 203    Print  

we can overload assignment operator as a normal function.But we can not overload assignment operator as friend function why?


  
Total Answers and Comments: 1 Last Update: September 15, 2005   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
September 15, 2005 08:34:00   #1  
sumanjit        

RE: we can overload assignment operator as a normal...
If the operation modifies the state of the class object it operates on it must be a member function not a friend fucntionThus all operator such as * + etc are naturally defined asmember functions not friend functionsConversely if the operator does not modify any of its operands but needs only a representation of the object it does not have tobe a member function and often less confusing.This is the reason why binary operators are often implemented asfriend functions sunch as + * - etc..
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    

 Related Questions

Ø      Public, protected and private are three access specifiers in C++.  Ø      Public data members and member functions are accessible 
Latest Answer : Private Protected and Public all these are access specifiers.Private Data Members are only available inside classProtected Data Members are  only available inside class as well as in derived classes.Public Data members are available ...

As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be 
Latest Answer : Friend function is used in OOP languages which allows a private or protected function to be accessed by a member outside a class. Any function outside a Class can be given access to work with members inside a class by simply writing a keyword friend ...

 A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually 
Latest Answer : It is a functions whose behaviour can be overriden with an inherited class by a function of same signature. It is an important part of OOPS and Polymorphism. ...

A scope resolution operator (::), can be used to define the member functions of a class outside the class.  
Latest Answer : Scope resolution:As the name itself indicates,it resolves global scope to local scopeEx:int a=10;int main(){a=20;cout

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms 
Latest Answer : C++ enables polymorphism - The ability of obejcts of different classes related by inheritance respond differntly to the same function call. ...

  Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This 
Latest Answer : Here are some examples1) Function overloadingclass FuncOver {public:      // Constructors can also be overloaded.      FuncOver();      // Overloaded constructor.      ...

Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. 
Latest Answer : virtual class :: It is an inner class which can be overriden by the derived classes. ...

 The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange 
Latest Answer : inline function is a function which extends the code when it is invoked. Otherwise is skip the code. ...

Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill 
Latest Answer : A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function. These function ...

Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known as namespaces.  The form to 
Latest Answer : Namespace is simply a name given to a global space, to form a sub-space in global space. ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Dereference Operator

C Dereference Operator In this C tutorial you will learn how to access the value of variables pointed by the pointer variables using pointer concept discussed in detail mosgoogle center It is possible to access the value of variables pointed by the pointer variables using pointer This is performed
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

C++ Function Passing Types

C Function Passing Types In this C tutorial you will learn about function passing types two types of arguments passing in functions passed by value  and  passed by reference are discussed here mosgoogle center The arguments passed to a function can be performed in two ways Passed
 

C++ Operator Overloading Part II

C Operator Overloading Part II Operator overloading is a very important aspect of object oriented programming Binary operators can be overloaded in a similar manner as unary operators In this C tutorial you will learn about Binary Operating Overloading explained along with syntax and example mosgoog
 

What is DECODE function used for?

DECODE is used to decode a CHAR or VARCHAR2 or NUMBER into any of several different character strings or numbers based on value. That is DECODE does a value-by-value substitution. For every value that is given in the DECODE function it makes an if then check and matches the value. The general format
 

printf() Function Return Value

What is the return value from printf() function? printf function always returns the number of characters printed. Let us understand this with an example: main() { int a=10; printf("%d",printf("%d %d %d", a,a,a)); } In this above program the inner printf i
 

How is the main() function declared?

The declaration of main can be done as int main() One more declaration that can be taken by main is command line arguments form int main(int argc, char *argv[]) or this can also be written as int main(argc, argv) int argc; char *argv[]; NOTE: It is not possible for one to declare the main
 

How does the function call within function get evaluated?

Whenever we have more than one function which is called for a finite number of times then such a function gets evaluated from inside out. Let us understand this concept with an example. For instance consider a function sample called within it 4 times as given in program below: main() { int a=50;
 

What happens when a variable is not initialized in main function?

When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below main() { int x; printf(“%d”,x); z= sample() } sample() { printf(“Testing program”); } Output is   &n
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape