🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3565

Re: overriding functions a la Stroustrup allow

#3565
From: Steve Clamage
Date: Fri, 01 Mar 1996 17:04
63 lines
2967 bytes
In article 41o@news.rwth-aachen.de, fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer) writes:
>In "Bjarne Stroustrup, The C++ programming language (german translation)"
>I found an example, which looks like this:
>
>struct base {
>  base *next;
>  static base *list;
>
>  base() {next = list; list = this};
>
>  virtual void function() = 0;
>  // ...
>};
>
>class derived : public base {
>  // ...
>public:
>  void function();
>  // ...
>};
>
>
>Two questions:
>
>1)  Does function() in class derived really override function() in base?

Yes.

>    Does the declaration in derived really say that function is not pure
>    virtual and not virtual at all? 

Yes, No. Since it has the same signature as a base-class virtual function,
it overrides that function and is virtual. That is, the derived-class
version is virtual whether you declare it virtual explicitly or not. It is
not pure virtual because it does not have "=0" as part of the declaration.

>    I get a linker error-message, when I
>    use such a construction without defining the overriding function, but
>    neither a compiler error nor a warning. Is this correct?

Yes. If you declare a non-pure virtual function, most implementations
require you to define it whether you call the function or not. The lack
of a definition is typically found during (one of) the linking phase(s).


>2)  What happens, when the very first object is created with a class
>    derived from base? The constructor of base assignes list to next, but
>    list is not yet initialized; so rubbish may be assigned to next. Is
>    there no need to initialize list first, e.g. base *base::list = 0; some-
>    where outside of base?

A static data member of a class requires a separate definition outside
the class. (The declaration inside the class is not a definition.)

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4h78mr$alj@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <4h4hmr$41o@news.rwth-aachen.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: overriding functions a la Stroustrup allow
Date: 01 Mar 1996 09:04:37 PST
Organization: Sun Microsystems Inc.
Approved: austern@isolde.mti.sgi.com
Message-ID: <4h78mr$alj@engnews1.Eng.Sun.COM>
References: <4h4hmr$41o@news.rwth-aachen.de>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 1 Mar 1996 16:30:19 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMTcuOUy4NqrwXLNJAQEf+wIApCaE1qAXm+WcGZjTXeHl+4MW3In5bZ8F
 o46RNVQZzwMVSQgvlHxJJfYLrnvoVT0YbDq/qkRTVn/Z1yixORM+eg==
 =bCxY
Originator: austern@isolde.mti.sgi.com