Re: how to call parent's operator = function?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael Leung (Leung__at_163.com)
Date: 05/21/04


Date: Thu, 20 May 2004 18:29:18 -0700

The answer to your question can be found in <<Effective C++>>. Mayers has
explained this very clearly in the book.

USE:

A::operator=(a);

but some old compilers will not accept such syntax. So you can do like
below:

static_cast<A&>(*this) = a;

"May Young" <tony@srac.com> wrote in message
news:40A54E60.4030400@srac.com...
> Hi,
>
> If a parent class and a child class both have an operator = function,
> how does the child's = function call its parent's = function? Thanks
> for your help. Tony
>
>
> class A
> {
> public:
> ...
> A& operator= (const A& a);
> };
>
> class AA : public A
> {
> public:
> AA& operator= (const AA& a);
>
> };
>
> A& A::operator= (const A& a)
> {
> ...
> return *this;
> }
>
> AA& AA::operator= (const AA& a)
> {
> *this A::operator= a; // ?????
> return *this;
> }
>



Relevant Pages

  • Re: The Decline of C/C++, the rise of X
    ... > added in, as in Delphi. ... > as C# is like a Delphi bred with java language i'll stick it in there. ... I believe there are native compilers even for Java, ... >> the syntax level this can be done by providing more expressive ...
    (comp.programming)
  • Declaration to get 8-bit (or 16-bit) integer?
    ... Supported by all the current compilers that I've tried it on. ... Not likely to become standard in the foreseeable future. ... Syntax standard-conforming, but semantics not guaranteed of course. ... The meaning of the code not obvious to anyone but a Fortran guru. ...
    (comp.lang.fortran)
  • Re: Declaration to get 8-bit (or 16-bit) integer?
    ... INTEGER*1:: abyte! ... Supported by all the current compilers that I've tried it on. ... Not likely to become standard in the foreseeable future. ... Syntax standard-conforming, but semantics not guaranteed of course. ...
    (comp.lang.fortran)
  • Re: new version of visual basic is going to be released
    ... That's right Jonathan. ... compilers can generate just as good code ... operator syntax, were simply to make life easier for the compiler. ... I'm seriously thinking of writing a book on language design, ...
    (microsoft.public.vb.general.discussion)
  • Re: new version of visual basic is going to be released
    ... compilers can generate just as good ... > the point that C was a language designed to be read by compilers, ... > operator syntax, were simply to make life easier for the compiler. ... you were conned into optimising your own source. ...
    (microsoft.public.vb.general.discussion)