added PureVirtual

This commit is contained in:
Darren Ranalli 2003-05-13 22:47:07 +00:00
parent befcfc7f23
commit 81d00c8bd6

View File

@ -662,3 +662,15 @@ def lineTag(baseFileName=1, verbose=0, separator=':'):
else: else:
return '%s%s%s%s%s' % (fileName, separator, lineNum, separator, return '%s%s%s%s%s' % (fileName, separator, lineNum, separator,
funcName) funcName)
class PureVirtual:
""" Python classes that want to have C++-style pure-virtual functions
can derive from this class and call 'derivedMustOverride' from their
'pure virtual' methods. Such Python classes can still be instantiated,
but they will give an informative error when a pure-virtual method
is invoked. """
def derivedMustOverride(self):
""" call this function from methods that must be overriden
and are not meant to be chained down to. This simulates C++
pure-virtual methods. """
raise 'error: derived class must implement %s' % callerInfo()[2]