summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-17 11:25:31 +0200
committerOskar <[email protected]>2024-09-17 11:25:31 +0200
commitc640d847343b3d50e7716173141d63bd1cca265c (patch)
tree7e897f005d7081dff9216f9092fa2fe084cf2288
parentf8b740c5b083cbb2d755b8d1adb7dea41563c9ac (diff)
small test
-rw-r--r--functionpointertest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/functionpointertest.cpp b/functionpointertest.cpp
new file mode 100644
index 0000000..7bca9ec
--- /dev/null
+++ b/functionpointertest.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <vector>
+
+/*
+ *
+ *
+ *
+ *
+ */
+
+int summing(int a, int b) {
+
+ return a + b;
+}
+
+int subtracting(int a, int b) {
+
+ return a - b;
+}
+
+int multiplying(int a, int b) {
+
+ return a * b;
+}
+
+int dividing(int a, int b) {
+
+ return a / b;
+}
+
+int fpfunction_as_argument(int(*calculate)(int, int), int a, int b) {
+
+ return calculate(a, b);
+}
+
+
+
+int main () {
+
+ int (*fpfp)(int, int) = summing;
+ int (*fpfp1)(int, int) = subtracting;
+ int (*fpfp2)(int, int) = multiplying;
+ int (*fpfp3)(int, int) = dividing;
+ std::vector<int(*)(int, int)> funcvec = {fpfp, fpfp1, fpfp2, fpfp3};
+ for(auto a : funcvec) {
+ std::cout << a(10, 10) << std::endl;
+ }
+
+ std::cout << std::endl;
+ std::cout << fpfunction_as_argument(multiplying, 10, 929) << std::endl;
+ return 0;
+}