aboutsummaryrefslogtreecommitdiff
path: root/Examples/pike/overload/example.cxx
blob: 3760fdd4936e98cfcdc6f79eed5e816f51a2c178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>

#include "example.h"

// Overloaded constructors for class Bar
Bar::Bar() {
    std::cout << "Called Bar::Bar()" << std::endl;
}

Bar::Bar(const Bar&) {
    std::cout << "Called Bar::Bar(const Bar&)" << std::endl;
}

Bar::Bar(double x) {
    std::cout << "Called Bar::Bar(double) with x = " << x << std::endl;
}

Bar::Bar(double x, char *y) {
    std::cout << "Called Bar::Bar(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}

Bar::Bar(int x, int y) {
    std::cout << "Called Bar::Bar(int, int) with x, y = " << x << ", " << y << std::endl;
}

Bar::Bar(char *x) {
    std::cout << "Called Bar::Bar(char *) with x = \"" << x << "\"" << std::endl;
}

Bar::Bar(int x) {
    std::cout << "Called Bar::Bar(int) with x = " << x << std::endl;
}

Bar::Bar(long x) {
    std::cout << "Called Bar::Bar(long) with x = " << x << std::endl;
}

Bar::Bar(Bar *x) {
    std::cout << "Called Bar::Bar(Bar *) with x = " << x << std::endl;
}

// Overloaded member functions
void Bar::foo(const Bar& x) {
    std::cout << "Called Bar::foo(const Bar&) with &x = " << &x << std::endl;
}

void Bar::foo(double x) {
    std::cout << "Called Bar::foo(double) with x = " << x << std::endl;
}

void Bar::foo(double x, char *y) {
    std::cout << "Called Bar::foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}

void Bar::foo(int x, int y) {
    std::cout << "Called Bar::foo(int, int) with x, y = " << x << ", " << y << std::endl;
}

void Bar::foo(char *x) {
    std::cout << "Called Bar::foo(char *) with x = \"" << x << "\"" << std::endl;
}

void Bar::foo(int x) {
    std::cout << "Called Bar::foo(int) with x = " << x << std::endl;
}

void Bar::foo(long x) {
    std::cout << "Called Bar::foo(long) with x = " << x << std::endl;
}

void Bar::foo(Bar *x) {
    std::cout << "Called Bar::foo(Bar *) with x = " << x << std::endl;
}

void Bar::spam(int x, int y, int z) {
    std::cout << "Called Bar::spam(int, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
}

void Bar::spam(double x, int y, int z) {
    std::cout << "Called Bar::spam(double, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
}

// Overloaded global methods
void foo(const Bar& x) {
    std::cout << "Called foo(const Bar& x) with &x = " << &x << std::endl;
}

void foo(double x) {
    std::cout << "Called foo(double) with x = " << x << std::endl;
}

void foo(double x, char *y) {
    std::cout << "Called foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}

void foo(int x, int y) {
    std::cout << "Called foo(int, int) with x, y = " << x << ", " << y << std::endl;
}

void foo(char *x) {
    std::cout << "Called foo(char *) with x = \"" << x << "\"" << std::endl;
}

void foo(int x) {
    std::cout << "Called foo(int) with x = " << x << std::endl;
}

void foo(long x) {
    std::cout << "Called foo(long) with x = " << x << std::endl;
}

void foo(Bar *x) {
    std::cout << "Called foo(Bar *) with x = " << x << std::endl;
}