I received such a task - to make a template function that can accept an int float string
and return half of the numbers and strings.
There are no ideas at all .. Here is a sketch that compiles but gives an error when calling ..
template <typename Type> Type max(Type a) { if (typeid(a).name()[0]=='A'){ // тип строка if (strlen(a)>1) { //больше одной буквы a[strlen(a)/2]='\0';} // режем пополам return a; //возвр строку }else{ return a/2;//вовр число } }
for example, what should be in the end Challenges:
int a = max(10); // 5 float b = max(5.8); //2.9 string c =max("Hashcode") //Hash
Help, please, or give an idea or an example of how to do it)