fork download
  1. #include <iostream>
  2.  
  3. template<typename T> struct identity { typedef T type; };
  4. template<typename T> inline T implicit_cast(typename identity<T>::type x) { return x; }
  5.  
  6. class Base {
  7. protected:
  8. Base(Base const&) { std::cout << "Base copy ctor"; }
  9.  
  10. template<typename T>
  11. Base(T&&) { std::cout << "universal Base ctor"; }
  12.  
  13. Base() {}
  14.  
  15. ~Base() {}
  16. };
  17.  
  18. class NotDeclared : private Base {
  19. // use implicit compiler-generated constructors
  20. };
  21.  
  22. class DeclaredDefault : private Base {
  23. public:
  24. DeclaredDefault(DeclaredDefault const&) = default;
  25.  
  26. DeclaredDefault() {}
  27. };
  28.  
  29. class DefinedPlain : private Base {
  30. public:
  31. DefinedPlain(DefinedPlain const& other) : Base(other) {}
  32.  
  33. DefinedPlain() {}
  34. };
  35.  
  36. class DefinedCastToBase : private Base {
  37. public:
  38. DefinedCastToBase(DefinedCastToBase const& other) : Base(implicit_cast<Base const&>(other)) {}
  39.  
  40. DefinedCastToBase() {}
  41. };
  42.  
  43. int main()
  44. {
  45. using std::cout; using std::endl;
  46.  
  47. NotDeclared nd;
  48. DeclaredDefault dd;
  49. DefinedPlain dp;
  50. DefinedCastToBase dctb;
  51.  
  52. cout << "NotDeclared : "; NotDeclared nd2(nd); cout << endl;
  53. cout << "DeclaredDefault : "; DeclaredDefault dd2(dd); cout << endl;
  54. cout << "DefinedPlain : "; DefinedPlain dp2(dp); cout << endl;
  55. cout << "DefinedCastToBase : "; DefinedCastToBase dctb2(dctb); cout << endl;
  56. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
NotDeclared       : Base copy ctor
DeclaredDefault   : Base copy ctor
DefinedPlain      : universal Base ctor
DefinedCastToBase : Base copy ctor