Last active
October 26, 2024 21:50
-
-
Save nam20485/63b78aef9ec22f2df9a7f2e4537d8a31 to your computer and use it in GitHub Desktop.
NonCopyable base class so you can inherit instead of implementing in every class
This file contains hidden or 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
#pragma once | |
class NonCopyable | |
{ | |
protected: | |
// 1. provide default ctor so it doesn't have to be explicitly defined in inherited classes | |
// 2. make NonCopyable class abstract so it can't be instantiated | |
NonCopyable() {} | |
/*virtual*/ ~NonCopyable() {} | |
private: | |
// no copy construction | |
NonCopyable(const NonCopyable&) {} | |
// no copy by operator= | |
NonCopyable& operator=(const NonCopyable&) {} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment