PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/ruby/overloading/example.cxx

#
C++ | 125 lines | 89 code | 32 blank | 4 comment | 0 complexity | 1615dec4422e7d7c23243b9f72afce35 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #include <iostream>
  2. #include "example.h"
  3. // Overloaded constructors for class Bar
  4. Bar::Bar() {
  5. std::cout << "Called Bar::Bar()" << std::endl;
  6. }
  7. Bar::Bar(const Bar&) {
  8. std::cout << "Called Bar::Bar(const Bar&)" << std::endl;
  9. }
  10. Bar::Bar(double x) {
  11. std::cout << "Called Bar::Bar(double) with x = " << x << std::endl;
  12. }
  13. Bar::Bar(double x, char *y) {
  14. std::cout << "Called Bar::Bar(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
  15. }
  16. Bar::Bar(int x, int y) {
  17. std::cout << "Called Bar::Bar(int, int) with x, y = " << x << ", " << y << std::endl;
  18. }
  19. Bar::Bar(char *x) {
  20. std::cout << "Called Bar::Bar(char *) with x = \"" << x << "\"" << std::endl;
  21. }
  22. Bar::Bar(int x) {
  23. std::cout << "Called Bar::Bar(int) with x = " << x << std::endl;
  24. }
  25. Bar::Bar(long x) {
  26. std::cout << "Called Bar::Bar(long) with x = " << x << std::endl;
  27. }
  28. Bar::Bar(Bar *x) {
  29. std::cout << "Called Bar::Bar(Bar *) with x = " << x << std::endl;
  30. }
  31. // Overloaded member functions
  32. void Bar::foo(const Bar& x) {
  33. std::cout << "Called Bar::foo(const Bar&) with &x = " << &x << std::endl;
  34. }
  35. void Bar::foo(double x) {
  36. std::cout << "Called Bar::foo(double) with x = " << x << std::endl;
  37. }
  38. void Bar::foo(double x, char *y) {
  39. std::cout << "Called Bar::foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
  40. }
  41. void Bar::foo(int x, int y) {
  42. std::cout << "Called Bar::foo(int, int) with x, y = " << x << ", " << y << std::endl;
  43. }
  44. void Bar::foo(char *x) {
  45. std::cout << "Called Bar::foo(char *) with x = \"" << x << "\"" << std::endl;
  46. }
  47. void Bar::foo(int x) {
  48. std::cout << "Called Bar::foo(int) with x = " << x << std::endl;
  49. }
  50. void Bar::foo(long x) {
  51. std::cout << "Called Bar::foo(long) with x = " << x << std::endl;
  52. }
  53. void Bar::foo(Bar *x) {
  54. std::cout << "Called Bar::foo(Bar *) with x = " << x << std::endl;
  55. }
  56. void Bar::spam(int x, int y, int z) {
  57. std::cout << "Called Bar::spam(int, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
  58. }
  59. void Bar::spam(double x, int y, int z) {
  60. std::cout << "Called Bar::spam(double, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
  61. }
  62. // Overloaded global methods
  63. void foo(const Bar& x) {
  64. std::cout << "Called foo(const Bar& x) with &x = " << &x << std::endl;
  65. }
  66. void foo(double x) {
  67. std::cout << "Called foo(double) with x = " << x << std::endl;
  68. }
  69. void foo(double x, char *y) {
  70. std::cout << "Called foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
  71. }
  72. void foo(int x, int y) {
  73. std::cout << "Called foo(int, int) with x, y = " << x << ", " << y << std::endl;
  74. }
  75. void foo(char *x) {
  76. std::cout << "Called foo(char *) with x = \"" << x << "\"" << std::endl;
  77. }
  78. void foo(int x) {
  79. std::cout << "Called foo(int) with x = " << x << std::endl;
  80. }
  81. void foo(long x) {
  82. std::cout << "Called foo(long) with x = " << x << std::endl;
  83. }
  84. void foo(Bar *x) {
  85. std::cout << "Called foo(Bar *) with x = " << x << std::endl;
  86. }
  87. // Overloaded global spam() functions
  88. void spam(int x, int y, int z) {
  89. std::cout << "Called spam(int, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
  90. }
  91. void spam(double x, int y, int z) {
  92. std::cout << "Called spam(double, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
  93. }