Created
November 29, 2018 20:55
-
-
Save AntonKueltz/8513b4564a34fd649508b822e142c90d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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