Topic: overriding functions a la Stroustrup allowed?
Author: fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer)
Date: 1996/03/01 Raw View
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?
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.
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.
]