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

What are constructors in oop?

0 Answers  


WAP to generate 2n+1 lines of the following pattern on the computer screen:

2 Answers  


What is the differances between a abstract calss and interface

5 Answers   Aviva, Symphony,


#include <string.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> void select(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); select(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void select(char *items, int count) { register int a, b, c; int exchange; char t; for(a = 0; a < count-1; ++a) { exchange = 0; c = a; t = items[ a ]; for(b = a + 1; b < count; ++b) { if(items[ b ] < t) { c = b; t = items[ b ]; exchange = 1; } } if(exchange) { items[ c ] = items[ a ]; items[ a ] = t; } } } design an algorithm for Selection Sort

0 Answers  


What is encapsulation c#?

0 Answers  






When a private constructer is being inherited from one class to another class and when the object is instantiated is the space reserved for this private variable in the memory??

13 Answers   HCL, Honeywell,


why constructor cannt be declar virtually? why destructor cannt be overloaded?

2 Answers   Infosys,


difference between static and non-static variables?

2 Answers  


Why static functions always uses static variables?

3 Answers  


which structured data type is not used in c++? 1.union 2.structure 3.string 4.boolean

2 Answers   HCL, Wipro,


explain dynamic binding by drowing

2 Answers   Cognizant,


what are the ways in which a constructors can be called?

2 Answers   TCS,


Categories