Skip to content

Instantly share code, notes, and snippets.

@nam20485
Last active October 26, 2024 21:50
Show Gist options
  • Save nam20485/63b78aef9ec22f2df9a7f2e4537d8a31 to your computer and use it in GitHub Desktop.
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
#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