-5
#include<conio.h>
#include<iostream>
using namespace std;
template<class T>
T min(T a,T b)
{
return (a>b)?a:b;
}
int main()
{
int x,y;
cin>>x>>y;
cout<<"min. of integer value is="<<min(x,y); //error is call of overloaded function    is ambiguous.
float p,q;
cin>>p>>q;
cout<<"min. of floating value is="<<min(p,q);//same error as above
char c1,c2;
cin>>c1>>c2;
cout<<"min. of c1 and c2(basis of ASCII values)="<<min(c1,c2);// same error as    above
getch();
return 0; }

Is there any inbuilt feature of dev c++ that doesnt support templates or is there some other error?

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
  • 4
    Dev-C++ is an IDE. If you're getting an error, it's from the compiler, unless you mean an Intellisense error. Also, use `std::min`. One reason for using it is that it actually returns the minimum, not the maximum. Anyway, the error says what I've just described. There are two equally valid templated `min` functions to choose from. This is a good reason to not throw `using namespace std;` in just for the heck of it. – chris Jun 27 '14 at 17:39
  • It's not clear what you mean by "templates are not running properly". Are you seeing errors during compilation? Are you seeing errors at run time? – R Sahu Jun 27 '14 at 17:43
  • @RSahu Compile time apperently (see comments in code). I edited accordingly. – Baum mit Augen Jun 27 '14 at 17:44
  • errors doing compilation.And the errors are "call of overloaded min(int&, int&) is ambiguous".. i am getting this error at the cout statement. – user3763047 Jun 27 '14 at 17:46
  • As @chris said, there's 2 `min` functions in your code: the one you defined and the one from the `std` namespace (`std::min()`). Since you have `using namespace std;` at the top of your file, then calling simply `min` isn't good enough for the compiler to understand which version of the two you want, hence it's ambiguous. – djikay Jun 27 '14 at 17:47
  • 2
    `#include` please get rid of this, you don't need it at all. – shuttle87 Jun 27 '14 at 17:49
  • @shuttle87, I don't know where people get the idea that they need to use `getch()` at the end of the program. Unfortunately, `conio.h` is needed for that. – R Sahu Jun 27 '14 at 17:51
  • @RSahu, Well, you don't need `getch()`. `getch()` is the only reason you have for including `conio.h`. Thus, you don't need `conio.h`. – chris Jun 27 '14 at 17:53
  • @chris, I agree with you. Only if we can get people to understand that they don't need to use `getch()`. – R Sahu Jun 27 '14 at 18:00
  • @RSahu, The only benefit that it offers is that you only need to press a single key. The same thing can be done without using a header meant for DOS by using `ReadConsoleInput`. Alternatively, I'm sure ncurses has something portable. You probably know this, but geez, that function is so old and unnecessary. Even pausing the program can be replaced with just running it in the console like it's meant to be run or telling the IDE not to close it. – chris Jun 27 '14 at 18:03

1 Answers1

1

The reason is there is a std::min, which gets imported into the global namespace (due to the using namespace std;).

So you have 2 different versions of min: Your version (which actually returns the maximum...), and the standard min.

Either rename your min-function, or remove it (and use std::min instead).

Sedenion
  • 5,421
  • 2
  • 14
  • 42