Skip to content

Instantly share code, notes, and snippets.

@AntonKueltz
Created November 29, 2018 20:55
Show Gist options
  • Save AntonKueltz/8513b4564a34fd649508b822e142c90d to your computer and use it in GitHub Desktop.
Save AntonKueltz/8513b4564a34fd649508b822e142c90d to your computer and use it in GitHub Desktop.
// timeKeeper.h
class TimeKeeper {
public:
TimeKeeper();
~TimeKeeper(); // note the virtual keyword is missing
};
// wristWatch.h
class WristWatch : public TimeKeeper {
};
// main.cpp
int main(int argc, char * argv[]) {
// suppose getTimeKeeper may return a WristWatch (legal syntax)
TimeKeeper *ptk = getTimeKeeper();
// without virtual destructor we would call the base class destructor
delete ptk; // undefined behavior!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment