templeteFunktion allgemein und speziell eingefügt

This commit is contained in:
2025-10-04 15:26:39 +02:00
parent dca133f8ea
commit 98bbf386bf
2 changed files with 38 additions and 3 deletions

View File

@@ -9,6 +9,12 @@ namespace ax{
std::cout << "Das doppelte der Zahl ist: " << x*2 << std::endl; std::cout << "Das doppelte der Zahl ist: " << x*2 << std::endl;
} }
void print_char(char x)
{
std::cout << x;
}
int sqrt(int x){ int sqrt(int x){
return x*x; return x*x;
@@ -17,4 +23,22 @@ namespace ax{
char shift(char x){ char shift(char x){
return x-1; return x-1;
} }
//allgmeine Funktion Deklaration ohne Argumente oder returns für einen unbekannten Datentyp
template<typename T> std::string type_name();
//Spezialisierte Implementation von type_name() für einen entsprechenden Datentyp vgl. mit überladung
template<> std::string type_name<int>() {return "Integer";}
template<> std::string type_name<char>(){return "Char";}
template<> std::string type_name<float>(){return "Float";}
template<> std::string type_name<double>(){return "Double";}
template<> std::string type_name<bool>(){return "Bool";}
template<typename T>
void ausgebene(T a){
std::cout << a << " ist vom Type " << type_name<T>()<< std::endl ;
}
} }

View File

@@ -1,8 +1,10 @@
#include <iostream> #include <iostream>
#include <string>
#include "ax_funktions.hpp" #include "ax_funktions.hpp"
int number = 12; int number = 12;
char Buchstabe = 'a';
main() main()
{ {
@@ -19,8 +21,17 @@ main()
ax::print_number(ax::sqrt(3)); ax::print_number(ax::sqrt(3));
std::cout << "a " << "wird zu: " << ax::shift('a')<< std::endl; for (int i = 0; i < 26; i++)
{
ax::print_char(Buchstabe+i);
std::cout<< " wird zu: " << ax::shift(Buchstabe + i)<< std::endl;
}
//test double testdouble = 3.1416;
ax::ausgebene(Buchstabe);
ax::ausgebene(42);
ax::ausgebene(true);
ax::ausgebene(testdouble);
}; };