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
|
#include <cstring> // strcmp
#include <iostream> // printing for test
template <typename T>
const T &minD(T const& a, T const& b)
{
std::cout << "minD(T const&)\n";
if (a > b)
{
return b;
}
else
{
return a;
}
}
char *minD(char * a, char * b)
{
std::cout << "minD(char*)\n";
if (strcmp(a, b) > 0)
{
return b;
}
else
{
return a;
}
}
template <typename T>
const T &minD(T const &a, T const &b, T const &c)
{
return minD(minD(a, b), c);
}
template <typename T>
const T *minD(T const *a, T const *b, T const *c)
{
return minD(minD(const_cast<T*>(a), const_cast<T*>(b) ), const_cast<T*>(c));
}
int main()
{
int val = minD(42, 7, 68);
const char * const s0 = "CSC";
const char * const s1 = "461";
const char * const s2 = "This is test";
const char *s = minD(s0, s1, s2);
std::cout << val << '\n';
std::cout << s << '\n';
}
|