3 ms·
Good example, was that from Effective C++? Widely repeated, yet wrong.
by blt 7y ago
Good example, was that from Effective C++? Widely repeated, yet wrong.
- rileymat2 7y agoI am not following. Sure you can, sure it may work now, but it seems like something that is a recipe for future bugs being created?
- plorkyeran 7y agoIt only causes problems if you try to delete it via a pointer to the base class. If your base class doesn't have any virtual functions then it's very unlikely that anyone would ever write code which tried to do that anyway, so it's not an issue. A base class with virtual functions but a non-virtual destructor is what'll get you into trouble down the road.
- BeetleB 7y ago>Widely repeated, yet wrong. Not right, either. Personally, I wouldn't inherit from a class that didn't have a virtual destructor unless I had a good reason. The point isn't whether it is right or wrong. Stating it as wrong is as problematic as stating it as right. The point is that whether it is OK to do it or not is an opinion, not a fact, and should be discussed as such.
- blt 7y agoyou are right, I was trying to say the "never" part is wrong but of course there is a good reason behind the advice; it's not pure bullshit.