- 방법1. member function을 private으로 선언하고 implementing을 하지 않음.
- 방법2. member function call을 막는 base 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
class Uncopyable { | |
protected: | |
Uncopyable() {}; | |
~Uncopyable() {}; | |
private: | |
Uncopyable(const Uncopyable&); | |
Uncopyalbe& operator=(const Uncopyable&); | |
}; | |
class Test: private Uncopyable{ | |
// ... | |
}; |
단, 이 경우 multiple inheritance 가 되어 empty base class optimization (Item 40) 같은 몇가지 사소한 문제를 일으킬 수 있음.
Summary
- To disallow functionality automatically provided by compilers, declare the corresponding member functions private and give no implementations. Using a base class like Uncopyable is one way to do this.
Reference
- Effective C++ by Scott Meyers
댓글 없음:
댓글 쓰기