🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: overriding functions a la Stroustrup allowed?

#3570
From: Steve Nutt
Date: Sun, 03 Mar 1996 21:22
56 lines
2476 bytes
fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer) wrote:

>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?
>    Does the declaration in derived really say that function is not pure
>    virtual and not virtual at all? 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?

I'm not totally sure what you are asking here, but it all looks OK.

The virtualness of function is inherited from base. It perhaps  makes
the code easier to understand if the virtual keyword is added to
derived.

>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? I get a compiler error, if I don't do it.

You should get a linker error rather than a compiler error if you
don't.

>Thanks in advance for any help,

>Rainer Fischer.
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Technical Details
Message-ID: <4hb90g$apu@post.acadia.net>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <4h4hmr$41o@news.rwth-aachen.de>

Show Full Headers
Complete Article Headers
From: steven2@salesbook.com (Steve Nutt)
Message-ID: <4hb90g$apu@post.acadia.net>
X-Original-Date: Sun, 03 Mar 1996 07:28:33 GMT
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 03 Mar 96 21:22:41 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: overriding functions a la Stroustrup allowed?
Organization: DET
References: <4h4hmr$41o@news.rwth-aachen.de>
Reply-To: steven2@salesbook.com
X-Newsreader: Forte Free Agent 1.0.82
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMToNueEDnX0m9pzZAQHcQwGAib5Z6kqDGDiSKx6bdY5Wc+LsarRzHmef
 8BoUtj+zAlDHH2FrSvrotupiR5oeugFh
 =AqKi