Topic: Based on what?


Author: jamshid@ses.com (Jamshid Afshar)
Date: 1995/03/31
Raw View
In article <3l9dlg$1tk@cedar.mr.net>, Brian Dellert <briand@ontrack.com> wrote:
>class bar {
>public:
> int funky() {return 1;};
>};
>class foo : public bar {
> typedef bar inherited;
>public:
> int funky() {return inherited::funky();}
>};
>
>I got the error
> 'bar::funky' : illegal call of nonstatic member function
>
>Did I misunderstand your suggestion, or does Microsoft misunderstand C++?
>(note: I get the same error even if the functions aren't inlined)

It's a Microsoft C++ bug.  Even compilers that have good, modern C++
implementations and have a history of tracking the ANSI/ISO committee
work have bugs when using such a typedef (not that ANSI/ISO has
changed anything in this area).  For example, IBM's xlC gives an error
when you use "inherited" in a base member initialization list, though
it allows your example:

 class Base {
 public:
     Base(int);
 };

 class Derived : public Base {
     typedef Base inherited;
 public:
     Derived(int i)
        : inherited(i)  // ARM legal, but xlC complains
     {}
 };

Cfront has bugs with it when the ctor is inline.  g++ 2.6.3 has no
problem with it, nor does BC++.

Jamshid Afshar
jamshid@ses.com





Author: kelley@debbie.fbsw.tt.com (Kevin Kelley)
Date: 1995/03/29
Raw View
In article <3la8ue$251@engnews2.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve Clamage) writes:
>From: clamage@Eng.Sun.COM (Steve Clamage)
>Subject: Re: Based on what?
>Date: 29 Mar 1995 00:17:18 GMT

>In article 1tk@cedar.mr.net, briand@ontrack.com (Brian Dellert) writes:
>>
>>I tried to compile the following code verbatim on MSVC+ 1.5:
>>
>>class bar
>>{
>>public:
>>       int funky() {return 1;};
>>};
>>
>>class foo : public bar
>>{
>>       typedef bar inherited;
>>
>>public:
>>       int funky() {return inherited::funky();}
>>};
>>
>>I got the error
>>       'bar::funky' : illegal call of nonstatic member function
>>
>>Did I misunderstand your suggestion, or does Microsoft misunderstand C++?
>>(note: I get the same error even if the functions aren't inlined)

>You understood the idiom correctly. Evidently it's a compiler bug,
>because the code is valid.


Class-local typedefs is evidently a tricky thing to implement; Borland
also had a problem compiling this construct until three or four major
versions ago.  It has worked correctly in all the 4.x versions, to my
knowledge.

(I get frustrated enough waiting for Borland to implement new things,
and there are very few extensions that they don't support almost
immediately.  I really can't resist this veiled slam at Microsoft's
incompiler.  :-)  )


Kevin Kelley <kelleyk@ccmail.tt.com>

>---
>Steve Clamage, stephen.clamage@eng.sun.com




        **    +                 '.          -<>-            o
      ******      O       O      ,'     _              o
      ******                     .    '(_).                      +
        **            O         ',                  kelleyk@ccmail.tt.com





Author: briand@ontrack.com (Brian Dellert)
Date: Tue, 28 Mar 95 16:31:40 GMT
Raw View
In article <3l8dvh$5ih@etca.etca.fr>,
   chris@alofi.etca.fr (Christian Millour) wrote:
>an extension was discussed, almost accepted, and finally dropped
>in favor of the following idiom
>
>class foo : public bar {
>  typedef bar inherited;
>  ...
>  int funky() {... return inherited::funky();}
>};
>

I tried to compile the following code verbatim on MSVC+ 1.5:

class bar
{
public:
 int funky() {return 1;};
};

class foo : public bar
{
 typedef bar inherited;

public:
 int funky() {return inherited::funky();}
};

I got the error
 'bar::funky' : illegal call of nonstatic member function

Did I misunderstand your suggestion, or does Microsoft misunderstand C++?
(note: I get the same error even if the functions aren't inlined)

thanks,
brian




Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 29 Mar 1995 00:17:18 GMT
Raw View
In article 1tk@cedar.mr.net, briand@ontrack.com (Brian Dellert) writes:
>
>I tried to compile the following code verbatim on MSVC+ 1.5:
>
>class bar
>{
>public:
> int funky() {return 1;};
>};
>
>class foo : public bar
>{
> typedef bar inherited;
>
>public:
> int funky() {return inherited::funky();}
>};
>
>I got the error
> 'bar::funky' : illegal call of nonstatic member function
>
>Did I misunderstand your suggestion, or does Microsoft misunderstand C++?
>(note: I get the same error even if the functions aren't inlined)

You understood the idiom correctly. Evidently it's a compiler bug,
because the code is valid.


---
Steve Clamage, stephen.clamage@eng.sun.com





Author: chris@alofi.etca.fr (Christian Millour)
Date: 28 Mar 1995 07:30:57 GMT
Raw View
In article <3l7555$jhi@cedar.mr.net>, briand@ontrack.com (Brian Dellert) writes:
|> Wouldn't it be nice if I could just write:
|>
|> int foo::funky()
|> {
|>  ...
|>  return base::funky();
|> }
|>
|> (where base referred to the immediate parent)

an extension was discussed, almost accepted, and finally dropped
in favor of the following idiom

class foo : public bar {
  typedef bar inherited;
  ...
  int funky() {... return inherited::funky();}
};

see D&E 13.6 for the full story.

--chris@etca.fr






Author: tony@online.tmx.com.au (Tony Cook)
Date: Wed, 29 Mar 1995 03:11:46 GMT
Raw View
Brian Dellert (briand@ontrack.com) wrote:
: Is there any way to generically call a base class member?  Let's say
: foo is derived from class bar, and foo's function funky() wants to call
: bar's funky() function.

: int foo::funky()
: {
:  ...
:  return bar::funky();
: }

: works, but this mucks things up if I decide to insert ewe into
: the hierarchy so foo is derived from ewe is derived from bar.
: If I forget to change my code to return ewe::funky(), we
: could be looking at one insidious bug.

This is like Smalltalk's super (I think).

What you can do is this:

class bar
{
  public:
    int funky();
};

class foo: public bar
{
  public:
    typedef bar base; // change this only if base class is changed
    int funky();
};

int foo::funky()
{
    return base::funky();
}

Of course this is more problematic if there are multiple base
classes.

Myself, I would prefer something like super built into the language.
--
        Tony Cook - tony@online.tmx.com.au
                    100237.3425@compuserve.com




Author: pete@borland.com (Pete Becker)
Date: 29 Mar 1995 03:33:16 GMT
Raw View
In article <3l9dlg$1tk@cedar.mr.net>, briand@ontrack.com (Brian Dellert) says:
>
>In article <3l8dvh$5ih@etca.etca.fr>,
>   chris@alofi.etca.fr (Christian Millour) wrote:
>>an extension was discussed, almost accepted, and finally dropped
>>in favor of the following idiom
>>
>>class foo : public bar {
>>  typedef bar inherited;
>>  ...
>>  int funky() {... return inherited::funky();}
>>};
>>
>
>I tried to compile the following code verbatim on MSVC+ 1.5:
>
>class bar
>{
>public:
>        int funky() {return 1;};
>};
>
>class foo : public bar
>{
>        typedef bar inherited;
>
>public:
>        int funky() {return inherited::funky();}
>};
>
>I got the error
>        'bar::funky' : illegal call of nonstatic member function
>
>Did I misunderstand your suggestion, or does Microsoft misunderstand C++?
>(note: I get the same error even if the functions aren't inlined)

 It works fine with BC 4.5, and I can't think of any reason that it
would not be legal.
 -- Pete




Author: briand@ontrack.com (Brian Dellert)
Date: Mon, 27 Mar 95 19:54:10 GMT
Raw View
Is there any way to generically call a base class member?  Let's say
foo is derived from class bar, and foo's function funky() wants to call
bar's funky() function.

int foo::funky()
{
 ...
 return bar::funky();
}

works, but this mucks things up if I decide to insert ewe into
the hierarchy so foo is derived from ewe is derived from bar.
If I forget to change my code to return ewe::funky(), we
could be looking at one insidious bug.

Wouldn't it be nice if I could just write:

int foo::funky()
{
 ...
 return base::funky();
}

(where base referred to the immediate parent)

?