Which is the only operator in C++ which can be overloaded
but NOT inherited?
Answers were Sorted based on User's Feedback
Answer / kalaivani
the '='(equal) operater can be overloaded but cannot be
inherited
Is This Answer Correct ? | 82 Yes | 1 No |
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 |
Answer / smita
"="this is the operator in C++ that can be overloaded but Not inherited
Is This Answer Correct ? | 20 Yes | 2 No |
Answer / lokesh
"=" is the only operator which can be overloaded but can not
be inherited
Is This Answer Correct ? | 12 Yes | 2 No |
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 |
Answer / hellboy
'this' operator. I mean the operator that is called as 'this'
Is This Answer Correct ? | 2 Yes | 13 No |
Petrol pump mgt. system: To design a program that display an interface for the sale of the Petrol and then make the entries at the backend in the database.
what is pointers
what is difference b/w object based and object oriented programming language?
18 Answers Chaitanya, College School Exams Tests, Educomp, IBM, Infosys, Telko,
what is diff between .net 1.1 and .net 2.0
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
What is public, protected, private?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
Can we call a base class method without creating instance?
Write a program to reverse a string using recursive function?
how to find the largest of given numbers in an array
What is differance between Abstract and Interface
What is a null tree?