answersLogoWhite

0


Best Answer

The pre-increment operator accepts no parameters and returns the same object (by reference) after incrementing.

The post-increment operator accepts an unused (dummy) integer parameter and returns a copy of the object (by value) that is made immediately prior to incrementing the object.

Note that it is good practice to always use the pre-increment operator even if a post-increment operator exists. The only time you should ever use a post-increment is when you actually store the return value. If you don't store the return value then you will end up making an unnecessary copy, which is highly inefficient. With primitive data types that are less than or equal in length to a pointer this isn't a major issue, but it's good practice nonetheless. If you do it for primitives then you're far more likely to remember to do it for class instances as well.

The following example emulates an integer type with pre-increment and post-increment operators implemented:

class Simple

{

public: // Construction:

Simple(int data = 0):m_data(data){}

Simple(const Simple& simple):m_data(simple.m_data){}

public:

// Assignment:

Simple& operator= (const Simple& simple) {

m_data = simple.m_data;

return( *this ); }

// pre-increment:

Simple& operator++ () { // no parameters!

++m_data; // increment this object

return( *this ); } // return a reference to this object

// post-increment:

Simple operator++(int) { // int parameter (not used)!

Simple copy( *this ); // call the copy constructor

++m_data; // increment this object

return( copy ); } // return the copy (by value)

private:

int m_data;

};

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the declaration of overloaded pre-increment operator implemented as member function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the correct declaration of the assignment operator overloaded function inside the travel class?

class travel {...travel &operator=( some type );... or ...travel operator=( some type );...};


Can static member function be overloaded?

Yes. Any function can be overloaded. However you cannot override a static member function. Only instance members can be overridden.


Differentitate between overload function and function template?

An overloaded function is a function that has two or more implementations that each operate upon a different type. Function templates allow the compiler to generate overloaded functions on an as required basis for any function where the implementations only differ by type.


What is meant by function declaration in C language?

The name of the function is established by what is called function declaration. It also establishes the number and the types of parameters.


What is local declaration?

Declarations inside a function is called local declaration


When a function is overloaded there are multiple definitions of the functions What makes the various definitions of the function different from each other?

Their parameter-lists and returns values.


What is the transport function implemented by both TCP and UDP?

IP


What is a global declaration?

A global declaration of a function or variable is a declaration that is at the global scope of the program, not inside another function. This means that the name will be visible within all functions in the program.


Where can the declaration of a function be placed?

The declaration of a function can be placed at, or anywere before its definition. It also needs to be placed prior to its first use.


What is the syntax of function?

Function declaration, definition, or calling? Pick one.


What is the function that eliminates the need to place the function definition before all calls to the function?

A forward declaration. In all statically typed languages (such as C++), all types must be declared before they can be used. A function is a type (the return value defines its type), but the compiler only needs to know how the function is called, not how it is implemented, so the function definition does not need to be visible to the compiler before the function can be called. The definition can actually be placed in another translation unit entirely. Note that a function definition is also a function declaration. Forward declarations make it possible for two functions to be dependent upon each other. A function declaration includes the return type, the name of the function and its argument types. The formal names of a function's arguments are not required in it's declaration, they are only required in its definition. A function's signature is the same as its declaration but excludes the return type. All calls to a function must match its signature. If the return type is used, it must be assigned to a type that is covariant with the declared type. Function declarations are typically placed in header files. By including the header in every translation unit that uses the function, we ensure the function's declaration is consistent across all translation units. If the function is defined in the same header it is declared, then it must also be declared inline. Multiple definitions of the same function are permitted provided they are token-for-token identical, thereby adhering to the one definition rule (ODR).


What is the function of the fuse or circuit breaker in a circuit?

A circuit breaker/fuse is designed to protect the wiring from getting overloaded.