call of overloaded 'min(int&, int&)' is ambiguous

前端 未结 5 532
梦如初夏
梦如初夏 2020-12-11 06:34

I got some problem on template.This code passed under vc6 but failed under g++. Is there anybody could tell me the reason? thanks.

#include
u         


        
相关标签:
5条回答
  • 2020-12-11 07:09

    instead of writing std::cout, u may use the namespace std, and create your function min in another namespace, say abc... so now when u call your function min, just write abc::min.. this should solve your problem.

    0 讨论(0)
  • 2020-12-11 07:20

    Probably you already have a definition for min() in g++.

    0 讨论(0)
  • 2020-12-11 07:31

    The function swap() is already exists in iostream. Therefore, it conflicts with your swap() function. You may have to specify that which swap() you want to use or change the name of your swap function like swap1(), swap2() etc. You could change any letter into UPPERCASE of your swap function like Swap() this could resolve the problem without removing using namespace std;

    otherwise, just remove using namespace std' and type

    using std :: cout;
    using std :: endl;
    

    instead OR write the code like -

    std :: cout << "After swapping - a = " << a << ", b = " << b << std :: endl;
    

    That's it. Thank you.

    0 讨论(0)
  • 2020-12-11 07:33

    It's because you've imported all of the std namespace, which is a no-no. Note the other candidates are template std::min. Remove the using namespace std; and either import select symbols:

    using std::cout;
    using std::endl;
    

    or qualify them:

    std::cout << "The smaller of " << i1 << " and " << i2 << " is " << i << std::endl;
    
    0 讨论(0)
  • 2020-12-11 07:34

    Your iostream include appears to also be bringing in the standard min call as well and the compiler can't figure out if you want the standard one (because of your using namespace) or your own. Just remove your own min and use the standard library's version.

    0 讨论(0)
提交回复
热议问题