Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 is pointers

7 Answers   Exilant,


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

1 Answers  


What is the types of inheritance?

0 Answers  


Precompilation ?

1 Answers   emc2,


I am DeePu sotware engineer working with EMC corporation ,recently I had attended mcafee interview . Their questions were at heights of stupidity , I don't know what they want , I am a developer with 4 year experienced .I am listing the questions asked 1:What is the flag in g++ to avoid structure padding 2:In wht order parameters are passed to stack 3:How you will edit code segment of an exe

1 Answers  


Hi All, I am new to programming and want to know how can i write a code to take input of 2 numbers from user and swap it without using a temp variable?

2 Answers   NIIT,


What is polymorphism in oops?

1 Answers  


How oops is better than procedural?

0 Answers  


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

0 Answers   TCS,


what is the advantage in software? what is the difference between the software developer and Engineer

1 Answers  


what is virtual function?

3 Answers  


what is graphics

0 Answers  


Categories