Can't get maximum from int and double

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  
#include <iostream>
#include<algorithm>
using namespace std;

int main()

{  int i=10;


    max(1,i);
   cout<<"The max(11.1,i) is "<<max(11.1,i);
    return 0;
}


it is showing an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

namespace my
{
    template < typename A, typename B > // note: unlike std::max(), returns a prvalue
    constexpr auto max( const A& a, const B& b ) { return a<b ? b : a ; }

    template < typename FIRST, typename... REST > // note: unlike std::max(), returns a prvalue
    constexpr auto max( const FIRST& first, const REST&... rest ) { return max( first, max(rest...) ) ; }
}

int main()
{
    std::cout << std::fixed << my::max( 11.1, 12 ) << '\n' // 12.00 (common type for double and int is double)
                            << my::max( 11.1, 12, 123LL ) << '\n' // 123.00
                            << my::max( 11.1, 12, 123LL, 'A', short(1234), 7.9f ) << '\n' ; // 1234.00

}

http://coliru.stacked-crooked.com/a/a2c1eecbdbd86240
Topic archived. No new replies allowed.