fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. namespace noncopyable_ // protection from unintended ADL
  5. {
  6.  
  7. class noncopyable
  8. {
  9. protected:
  10.  
  11. noncopyable()
  12. {
  13. std::cout << "default noncopyable()/n";
  14. }
  15. ~noncopyable() {}
  16.  
  17. //private:
  18. noncopyable(const noncopyable& that)
  19. {
  20. std::cout << "copy noncopyable()/n";
  21. }
  22. const noncopyable& operator=(const noncopyable& that);
  23. };
  24.  
  25. } // namespace noncopyable_
  26.  
  27. typedef noncopyable_::noncopyable noncopyable;
  28.  
  29. class Test : private noncopyable
  30. {
  31. public:
  32. Test() : m_val() {}
  33. Test(const Test& other) : m_val(other.m_val) {}
  34. ~Test() {}
  35.  
  36. private:
  37. int m_val;
  38. };
  39.  
  40. int main()
  41. {
  42. Test t1;
  43. Test t2(t1);
  44. std::cout << "end of test./n";
  45. return 0;
  46. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
default noncopyable()/ndefault noncopyable()/nend of test./n