Write a program to implement operator functions, C/C++ Programming

Assignment Help:

Implementing Operator Functions

The general format of the Operator function is:

return_type operator op ( argument list );

 

Where op is the symbol for the operator being overloaded. Op has to be a valid C++ operator, a new symbol cannot be used.

e.g.

Let us consider an example where we overload unary arithmetic operator '++'.

                class Counter

                 {

                  public :

                                                Counter();

                                                void operator++(void);

                  private :

                                                int Count;

 

      };

                Counter::Counter()

                 {

                                Count = 0;

                 }

                                void Counter::operator++(void)

                 {

                                ++ Count ;

                 }

 

                void main()

                 {

                   Counter c1;

 

                                c1++;                                     // increments Count to 1

                                ++c1;                                     // increments Count to 2

                 }

 


Related Discussions:- Write a program to implement operator functions

Define the system oriented data files, Define the System Oriented Data File...

Define the System Oriented Data Files? System-oriented data files are further closely related to the computer's operating system than Stream- oriented data files and they are s

Are comments included during compilation stage, Are comments included durin...

Are comments included during compilation stage and placed in EXE file as well? - No, comments encountered by compiler are disregarded. - Their only purpose is ease and guida

Explain reusability, Reusability  Reusability means reusing code writte...

Reusability  Reusability means reusing code written earlier, may be from some earlier project or from the library. Reusing old code not only saves development time, but also sa

Using only arrays, write c program to do the following : -fill 2 dimensiona...

write c program to do the following : -fill 2 dimensional array (square matrix array with size=4). -ask the user to enter any integer number and add this number to the diagonals -o

Doubt!, find the greater of the two variables, without using conditional lo...

find the greater of the two variables, without using conditional loops or ternary operators?

Calculation of mortgage interest rates, 1. When developing this project in ...

1. When developing this project in a Win32 Console Applications that includes the precompiled headers, enter in the Name: box, PRJ2[Your Full Last Name][Your First Initial] with no

Friend funtion.., Is friend function can be harmfull to make a secure progr...

Is friend function can be harmfull to make a secure program/sofware?

Binary search in array: - c program, Binary search in array: - C program: ...

Binary search in array: - C program: Write a program in c to define binary search in array. void main()                 {                 clrscr();

New customer, #questionhow can i add new customer and alot him a new unique...

#questionhow can i add new customer and alot him a new unique id ..

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd