metrowerks

Is there a way to prevent a method from being overridden in subclasses?

折月煮酒 提交于 2019-11-28 08:06:39
Is anyone aware of a language feature or technique in C++ to prevent a child class from over riding a particular method in the parent class? class Base { public: bool someGuaranteedResult() { return true; } }; class Child : public Base { public: bool someGuaranteedResult() { return false; /* Haha I broke things! */ } }; Even though it's not virtual, this is still allowed (at least in the Metrowerks compiler I'm using), all you get is a compile time warning about hiding non-virtual inherited function X. A couple of ideas: Make your function private. Do not make your function virtual. This doesn

Is there a way to prevent a method from being overridden in subclasses?

…衆ロ難τιáo~ 提交于 2019-11-27 02:04:36
问题 Is anyone aware of a language feature or technique in C++ to prevent a child class from over riding a particular method in the parent class? class Base { public: bool someGuaranteedResult() { return true; } }; class Child : public Base { public: bool someGuaranteedResult() { return false; /* Haha I broke things! */ } }; Even though it's not virtual, this is still allowed (at least in the Metrowerks compiler I'm using), all you get is a compile time warning about hiding non-virtual inherited