class_a.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/class_a.cpp source file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman, Itay Maman
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #include <algorithm> // for std::swap
  13. #include <sstream>
  14. #include <iostream>
  15. #include <assert.h>
  16. #include "class_a.h"
  17. using namespace std;
  18. class_a::~class_a()
  19. {
  20. assert(self_p_ == this);
  21. }
  22. class_a::class_a(int n)
  23. {
  24. n_ = n;
  25. self_p_ = this;
  26. }
  27. class_a::class_a(const class_a& other)
  28. {
  29. n_ = other.n_;
  30. self_p_ = this;
  31. }
  32. class_a& class_a::operator=(const class_a& rhs)
  33. {
  34. class_a temp(rhs);
  35. swap(temp);
  36. return *this;
  37. }
  38. void class_a::swap(class_a& other)
  39. {
  40. std::swap(n_, other.n_);
  41. }
  42. int class_a::get() const
  43. {
  44. return n_;
  45. }
  46. std::ostream& operator<<(std::ostream& strm, const class_a& a)
  47. {
  48. return strm << "class_a(" << a.get() << ")";
  49. }