Which is the only operator in C++ which can be overloaded
but NOT inherited?

Answers were Sorted based on User's Feedback



Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / kalaivani

the '='(equal) operater can be overloaded but cannot be
inherited

Is This Answer Correct ?    82 Yes 1 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / anban

basically "=" is the operator that cannot be inherited but
can
be overloaded..hope u got it.

Is This Answer Correct ?    37 Yes 0 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / smita

"="this is the operator in C++ that can be overloaded but Not inherited

Is This Answer Correct ?    20 Yes 2 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / lokesh

"=" is the only operator which can be overloaded but can not
be inherited

Is This Answer Correct ?    12 Yes 2 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / abcd

Ok I think instead of 5 same answers Someone should explain
why it is designed liek this?

Why it can not be inherited?

Is This Answer Correct ?    1 Yes 0 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / sharathnasa

#include <iostream>
#include <iomanip>

using namespace std;

class A {
public:
int _i;
A(int i) : _i(i) { }
virtual A &operator=(A const &other) {
if (this!=&other) {
_i = other._i;
}
return *this;
}
virtual A operator+(A const &rvalue) {
return A(_i + rvalue._i);
}
virtual void print() {
cout << "A(_i=" << _i << ")";
}
};

class B : public A {
public:
int _j;
B(int i, int j) : A(i), _j(j) { }
virtual void print() {
cout << "B(_i=" << _i << ", _j=" << _j <<")";
}
};

int main() {
A a1(5), a2(3);
a1.print();
cout << " + ";
a2.print();
cout << " = ";
A a3 = a1 + a2;
a3.print();
cout << endl;

B b1(5,3), b2(3,5);
b1.print();
cout << " + ";
b2.print();
cout << " = ";

// this works, although (b1+b2) returns an A since it uses
A's operator+
(b1+b2).print();

// this does not work: no conversion from A to B, i.e.
operator= not inherited
// B b3 = b1 + b2;
// b3.print();
cout << endl;

return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / hellboy

'this' operator. I mean the operator that is called as 'this'

Is This Answer Correct ?    2 Yes 13 No

Which is the only operator in C++ which can be overloaded but NOT inherited?..

Answer / devvrat

+

Is This Answer Correct ?    8 Yes 40 No

Post New Answer

More OOPS Interview Questions

why function overloading is not called as pure polymorphism?

2 Answers  


When you define a integer it gets stored in which data structure?(Stack or a heap)

2 Answers   emc2,


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

0 Answers  


The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 14 such programmers take 14 minutes to write 14 lines of code in total. How long will in take 5 programmers to write 5 lines of code in total ?

6 Answers   TCS,


DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.

5 Answers  






State what is encapsulation and friend function?

0 Answers   BirlaSoft,


Why do we use polymorphism in oops?

0 Answers  


What is the purpose of enum?

0 Answers  


Why is polymorphism important in oop?

0 Answers  


What are the 4 main oop principles?

0 Answers  


What are constructors in oop?

0 Answers  


any one please tell me the purpose of operator overloading

0 Answers   Amazon,


Categories