GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 201 of 203    Print  
Unary Postfix Operator Overloading
Which of the following statements accurately describe unary postfix operator++ overloading in C++?

A. It can be overloaded with no parameters when the operator function is a class member.

B. It can only be overloaded if the operator function is a class member.

C. It can be overloaded with one parameter when the operator function is free standing function (not a class member).

D. To overload it at least on parameter for the declaration is required.



  
Total Answers and Comments: 2 Last Update: October 15, 2009     Asked by: dlee6565 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 07, 2009 18:27:47   #1  
AlexeyP Member Since: October 2009   Contribution: 4    

RE: Unary Postfix Operator Overloading

D.

Postfix requires an int parameter. With no parameters you will be overloading prefix.

Also postfix should return by value and of course it has to be a class method and not a freestanding function.

Class Type
{
...
Type& operator++ () // prefix
{

Increment(*this); // whatever you want it to mean...

return *this; // return the resulting value by reference

};

Type operator++ (int) // dummy not used

{

Type temp *this;

++(*this); // implement postfix in terms of prefix

return temp; // return the original value by value

}
}


 
Is this answer useful? Yes | No
October 15, 2009 17:17:40   #2  
AlexeyP Member Since: October 2009   Contribution: 4    

RE: Unary Postfix Operator Overloading
In the previous

Increment(*this); // whatever you want it to mean...

was meant to be pseudocode.

Taken literally it will pass this object by value and therefore do nothing to it.

I should have written simply

Increment();

 
Is this answer useful? Yes | No

 Related Questions

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.      ...

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. ...

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching 
Latest Answer : Virtual constructor is not build-in C++ feature but it doesn't mean its not used by devs in code and in conversations. There are many other things that doesn't exist in particular language yet, people find ways around to solve it (SingleTon, Virtual Constructor, ...

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

What is the Basic nature of "cin" and "cout" and what concept or principle we are using on those two?
Basically "cin and cout" are INSTANCES of istream and ostream classes respectively.And the concept which is used on cin and cout is operator overloading. Extraction and Insertion operators are 

Latest Answer : New operator allows to allocate a memory from the heap, so a new instance of a class is created but operator New is used to overload the (new) operator just like overloading of other operators. Additionally: The term "operator new" is ...
Read Answers (5) | Asked by : suman

Latest Answer : All the above answers are right this is one more refinement.overridding is runtime polymorphism while overloading is compile time polymorphism.  ...
Read Answers (3) | Asked by : suji

Latest Answer : Inspite of repeated requests by some (few) sensible people to everybody to read the question properly before responding, nobody listens.For doreen, the question does not ask you to explain deep copy and shallow copy mechanism neither does is asks how ...
Read Answers (3) | Asked by : suji


 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++ 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
 

sizeof Operator

What is sizeof operator? sizeof will return the number of bytes reserved for a variable or data type. The sizeof operator is a compile-time operator that returns an integer value. In other words since sizeof is a compile time operator, when used in a expression, it does not get compiled into executa
 

Modulus Operator

What is the functionality and restrictions of Modulus Operator? When a division is performed, the remainder of the operation is given by modulus operator. The modulus operator is denoted in c by symbol %. For instance we have two integer values x and y, the operation x % y called as x modulus y give
 

Operator, Operand and Expression in C

Operator, Operand, and Expression in are symbols which take one or more operands or expressions and perform arithmetic or logical computations. Types of operators available in C are as follows: Arithmetic Assignment Logical/relational Bitwise These have operators under each
 

Prefix and Postfix Operator

How does the prefix and postfix operator on expression? The operators present in prefix and postfix are prefix increment operator denoted by ++ prefix decrement operator denoted by -- postfix increment operator postfix decrement operator The difference between the two is that i
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

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