Disabling inherited method on derived class

I don’t think it is possible. However you can further refine the Shape class by removing the rotate() method from its specification and instead define another subclass of Shape called RotatableShape and let Circle derive from Shape and all other Rotatable classes from RotatableShape. e.g: public class Shape{ //all the generic methods except rotate() } … Read more

Calling the base class constructor from the derived class constructor

The constructor of PetStore will call a constructor of Farm; there’s no way you can prevent it. If you do nothing (as you’ve done), it will call the default constructor (Farm()); if you need to pass arguments, you’ll have to specify the base class in the initializer list: PetStore::PetStore() : Farm( neededArgument ) , idF( … Read more

Why doesn’t a derived template class have access to a base template class’ identifiers?

That’s two-phase lookup for you. Base<T>::NO_ZEROFILL (all caps identifiers are boo, except for macros, BTW) is an identifier that depends on T. Since, when the compiler first parses the template, there’s no actual type substituted for T yet, the compiler doesn’t “know” what Base<T> is. So it cannot know any identifiers you assume to be … Read more

Cast base class to derived class python (or more pythonic way of extending classes)

If you are just adding behavior, and not depending on additional instance values, you can assign to the object’s __class__: from math import pi class Circle(object): def __init__(self, radius): self.radius = radius def area(self): return pi * self.radius**2 class CirclePlus(Circle): def diameter(self): return self.radius*2 def circumference(self): return self.radius*2*pi c = Circle(10) print c.radius print c.area() … Read more