[issue5349] abstractmethod vs C++ pure virtual

Jared Grubb report at bugs.python.org
Mon Feb 23 06:11:39 CET 2009


New submission from Jared Grubb <python at jaredgrubb.com>:

On page library/abc.html documenting abc.abstractmethod, the following
text about C++ is placed in a note:

"Note: Unlike C++’s pure virtual functions, or Java abstract methods,
these abstract methods may have an implementation. This implementation
can be called via the super() mechanism from the class that overrides
it. This could be useful as an end-point for a super-call in a framework
that uses cooperative multiple-inheritance."

This is not an accurate description of C++'s pure virtual functions.
Pure virtual functions CAN have an implementation, which can be called
from derived classes; this makes them behave just like Python's
abstractmethod.

Example:
struct Abstract {
   virtual void foo() = 0;
};
void Abstract::foo() {
   std::cout << "pure virtual function called";
}
struct Derived : public Abstract {
   virtual void foo() { 
       Abstract::foo(); // call the abstract impl
   }
};

----------
assignee: georg.brandl
components: Documentation
messages: 82618
nosy: georg.brandl, jaredgrubb
severity: normal
status: open
title: abstractmethod vs C++ pure virtual
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5349>
_______________________________________


More information about the Python-bugs-list mailing list