delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/07/11:03:18

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Virtual functions
Date: Fri, 06 Jun 1997 14:04:51 -0700
Organization: Alcyone Systems
Lines: 40
Message-ID: <33987B73.720B511@alcyone.com>
References: <3 DOT 0 DOT 16 DOT 19970605110638 DOT 2d5f362a AT hem1 DOT passagen DOT se>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Peter Palotas wrote:

> Is there some way I can call the parent::foo() from within child::foo()?
> Or
> is this just impossible?

Sure.  The syntax is exactly what you used.  You can use the scope
resolution operator (::) to call base member functions:

    class parent
    {
      public:
        virtual int foo(void);
    };

    class child: public parent
    {
      public:
        int foo(void);
    };

    int child::foo(void)
    {
        parent::foo();

        // ...
    }

Note that if this were all you wanted to do (i.e., call the parent member
functions and nothing more), then you wouldn't need to declare the virtual
function in the derived class in the first place, since it would already
have that behavior.

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
     "Covenants without the sword / are but words."
                                 / Camden

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019