Question

Why do we overload operators for programmer created data types (i.e. objects defined by creating a...

Why do we overload operators for programmer created data types (i.e. objects defined by creating a class)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Operators by default, overloaded for primitive data types and not for user defined types.

Compiler doesn't know what to perform, when operators are used on user defined types.

Hence the programmer has to explicitly overload the operator for the user defined types for which that operation has to be performed.

Add a comment
Know the answer?
Add Answer to:
Why do we overload operators for programmer created data types (i.e. objects defined by creating a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 12. Why would a programmer want to overload operators rather than use regular member functions to...

    12. Why would a programmer want to overload operators rather than use regular member functions to perform similar operations? 13. What is passed to the parameter of a class’s operator= function? 14. Why shouldn’t a class’s overloaded = operator be implemented with a void operator function?

  • Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class...

    Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. Write public set methods to set the values for length and width. Write...

  • c++) explain your answer. Suppose Data is a programmer-defined data type. You want to overload the...

    c++) explain your answer. Suppose Data is a programmer-defined data type. You want to overload the << operator and allow cascaded function calls. Which of the following is the best function header? explain your answer. a. ostream operator<<( ostream &output, const Data &dataToPrint ) b. ostream operator<<( const Data &dataToPrint, ostream &output ) c. ostream& operator<<( const Data &dataToPrint, ostream &output ) d. ostream& operator<<( ostream &output, const Data &dataToPrint )

  • Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then...

    Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...

  • QUESTION 18 According to class materials, the program is allowed to overload operators only if at...

    QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...

  • C++ (5 pts in total) Step 1: Operator Overload (3pts) Let's revisit your lab 5. Make...

    C++ (5 pts in total) Step 1: Operator Overload (3pts) Let's revisit your lab 5. Make an operator overload function for comparing shapes based on their area. For example, you want to have the ability to compare two shapes using the > and < operators, such as if ($1 > s2). In order to do this, you need to make an operator overload for > and < bool operator>(const Shape &, const Shape &); bool operator<(const Shape &, const Shape...

  • The creators of C++ have created primitive data types to allow developers to store numbers of various size they expect most users will need. Such as short, int, double. In our case we want to expand o...

    The creators of C++ have created primitive data types to allow developers to store numbers of various size they expect most users will need. Such as short, int, double. In our case we want to expand on these primitive data types and allow users to store big numbers that can store up to 1,000 digits long. In order to do this, you will create a BigNumbers class that will use vectors from STL to store the digits. BigNumbers should have...

  • 1. Why do we need to assign an internal IP address (i.e., behind NAT) for Metasploitable2-Linux?...

    1. Why do we need to assign an internal IP address (i.e., behind NAT) for Metasploitable2-Linux? What will happen if we assign a public IP to it? 2. Besides the two vulnerabilities Vsftpd v2.3.4 Backdoor and Vsftpd v2.3.4 Backdoor that we used, exploit three vulnerability using msfconsole. Show me that you have placed a file in the exploited remote machine via screenshots and by creating the file with the command “touch ” where should be replaced with your full name.

  • Why do we no longer study the IS-LM model in economics? (i.e. why is it now...

    Why do we no longer study the IS-LM model in economics? (i.e. why is it now considered the IS model instead?)

  • In c++ What does operator overloading allow us to do ? Why must the << and...

    In c++ What does operator overloading allow us to do ? Why must the << and the >> operators be overloaded as friend functions instead of member functions, for a user defined class ? What is the difference between an instance member variable and a static member variable ? How are call to static member functions made ? Describe the difference between reading a file using the >> operator and with the getline function What is inheritance What is a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT