Question

c++)Which situation would require the operator to be overloaded as a non-member function? provide an example...

c++)Which situation would require the operator to be overloaded as a non-member function? provide an example of your answer choice of when this would occur.

a. The overloaded operator is =.

b. The left operand is an int.

c. The operator returns a reference.

d. The left operand must not be a class object (or a reference to a class object).

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

The left operand is an int.

if left operand is of class type, then we use member function for assignment operator.
but, if we use int as left operand, then we must use a non-member function for assignment operator.
Add a comment
Know the answer?
Add Answer to:
c++)Which situation would require the operator to be overloaded as a non-member function? provide an example...
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
  • 1. Write a virtual member function named length , which specifies that the function is constant...

    1. Write a virtual member function named length , which specifies that the function is constant (that is does not modify the member data) and returns the square root of x squared plus y squared. 2.write the operator << function to have a member of the ostream class as its left hand operand and a member of the Two Dimensions class as its right hand operand. This function shall take the left hand operand by reference, This function shall return...

  • C++ questions T/F The compiler will report an error if the + operator is overloaded in...

    C++ questions T/F The compiler will report an error if the + operator is overloaded in a way so that it performs subtraction. T/F When a unary operator is overloaded using a member function, it accepts one explicit argument and returns a class object. T/F The size of an operator cannot be overloaded. T/F Operator overloading also allows creation of new operators. T/F To convert a class object to basic data type, a conversion operator needs to be included publicly...

  • 27. Suppose the unary ! operator is an overloaded member function of class String. For a...

    27. Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression Is? a. s.operator!0 b. s.operator!(default valuel, default value?,...) c. operator!(s d. A compiler error results because no arguments are given 28. Select the false statement regarding inheritance. a. A derived class can contain more attributes and behaviors than its base class b. A derived class can be the...

  • Project 1 - Operator Overloading (FlashDrive 2.0) In C++, many of the keyboard symbols that are...

    Project 1 - Operator Overloading (FlashDrive 2.0) In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...

  • Part t True er Fahe ( pts each) Tue or false? true F or fase -C++8...

    Part t True er Fahe ( pts each) Tue or false? true F or fase -C++8 generally regarded as a low-level language. Given x S, y 3, the exprossion (x<y)&& ((y > 0) 11 (y-= x + 2)) istrue hh writing computer pograms, it's best practice to write all your functions and the entire pogram, befbre testing any one of the functions or program segments by itself Operators have inputs and return outputs. When an arthmetie operator has been overloaded...

  • Can anyone explain this? 1. Suppose the following function is in the application program that uses...

    Can anyone explain this? 1. Suppose the following function is in the application program that uses the Coord class (Coord_app.cpp): int print_x(int x) { return x; } And we want to be able to do the following in main: int main() { Coord C1(5, 8); cout << get_x(C1) << endl; } The idea is that the function get_x expects an integer to be passed to it, but if a Coord object is passed to the function it will be converted...

  • Overview This checkpoint is intended to help you practice the syntax of operator overloading with member...

    Overview This checkpoint is intended to help you practice the syntax of operator overloading with member functions in C++. You will work with the same money class that you did in Checkpoint A, implementing a few more operators. Instructions Begin with a working (but simplistic) implementation of a Money class that contains integer values for dollars and cents. Here is my code: /********************* * File: check12b.cpp *********************/ #include using namespace std; #include "money.h" /**************************************************************** * Function: main * Purpose: Test...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p;...

    Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p; int i; int k; i = 42; k = i; p = &i; After these statements, which of the following statements will change the value of i to 75? A. k = 75; B. *k = 75; C. p = 75; D. *p = 75; E. Two or more of the answers will change i to 75. Consider the following statements: int i =...

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
ADVERTISEMENT