| ▲ | scotty79 a day ago | |||||||||||||||||||
I don't get what's bad about rule 7. And I haven't really programmed in C++ for a decade. When you are calling derived object through a base class pointer you have a choice if you want to call the function of the base class or the function of the derived class. If you don't make it virtual it's called by pointer type, if you do, it's called by pointee type. Same goes for the destructors with only difference being that in case of virtual destructor the deatructor of a base class will be called automatically after the destructor of the derived class. So basically if you want to override methods or the destructor make your functions virtual, including the destructor. Does it lead to problems? Surely. Should all metods be virtual by default? Probably. Should there be some keyword that indicates in derived class that a method intentionally shadows a non virtual method from the base class? Yes. It's not a great human oriented design but it's consistent. | ||||||||||||||||||||
| ▲ | chuckadams a day ago | parent [-] | |||||||||||||||||||
Apologies, I was referring to a "Rule of 7", but I more or less hallucinated it, since I'd heard the old "rule of 3" then "rule of 5" had been revised again, and thought they were maybe going with prime numbers? https://en.cppreference.com/w/cpp/language/rule_of_three.htm... The confusion kind of speaks for itself. The language is a construction set where the primary building block is razor blades. | ||||||||||||||||||||
| ||||||||||||||||||||