[comp.lang.c++] Calling Parent functions in Child???

<ACPS2924@Ryerson.Ca> (05/12/91)

If one has the following situation :

class A { int isEqual{}; }

class B : public A { int isEqual{} }


B::isEqual()
{
    return (... && // here i want to call the parents isEqual
                   // how do i do it??

}


I want to call the parents matching call inside the childs call.
In smalltalk you use super how is it done in C++.

Peter
+----------------------------------------------------------------------+
acps2924@ryerson.ca ! Who is the  ! If plumbers designed toilets like
                    ! user,pray,  ! software professionals design tools,
                    ! and who is  ! we'd be up to our knees in crap.
                    ! the used ?  !                 - Charles A. Rovira
+----------------------------------------------------------------------+

cadsi@ccad.uiowa.edu (CADSI) (05/14/91)

From article <91132.113932ACPS2924@Ryerson.Ca>, by ACPS2924@Ryerson.Ca:
> If one has the following situation :
> 
> class A { int isEqual{}; }
> 
> class B : public A { int isEqual{} }
> 
> 
> B::isEqual()
> {
>     return (... && // here i want to call the parents isEqual
>                    // how do i do it??
> 
> }
> 
> 
> I want to call the parents matching call inside the childs call.
> In smalltalk you use super how is it done in C++.

A::isEqual();

|----------------------------------------------------------------------------|
|Tom Hite					|  The views expressed by me |
|Manager, Product development			|  are mine, not necessarily |
|CADSI (Computer Aided Design Software Inc.	|  the views of CADSI.       |
|----------------------------------------------------------------------------|

ml27192@uxa.cso.uiuc.edu (Mark Lanett) (05/14/91)

ACPS2924@Ryerson.Ca writes:

>I want to call the parents matching call inside the childs call.
>In smalltalk you use super how is it done in C++.

Qualify the name: '<parent>::<function> (<parameters>)'
--
//-----------------------------------------------------------------------------
Mark Lanett						ml27192@uxa.cs.uiuc.edu
Software Tools Group, NCSA				mlanett@ncsa.uiuc.edu
To create a Mac emulator you would only need to write a screensaver for Windows
that draws a bomb box.

s892992@minyos.xx.rmit.oz.au (Bossman) (05/15/91)

ACPS2924@Ryerson.Ca writes:

>If one has the following situation :

>class A { int isEqual{}; }

>class B : public A { int isEqual{} }

>B::isEqual()
>{
>    return (... && // here i want to call the parents isEqual
>                   // how do i do it??
>}

   Inside the isEqual member function of B, a call to isEqual will result in
a recursive call back to the same member funcion. To call A's version of
isEqual, you need to use scope resolution. You can do this as follows:
 
B::isEqual()
{
    return (... && A:isEqual() );
}

Simple huh! In fact the call to B's isEqual() member function can be structured
the same way (ie: B::isEqual() ), but it is implicit that you are calling B's
member functions from within a member of B.
 
See ya,
       Kendall Bennett.