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

前端 未结 5 533
梦如初夏
梦如初夏 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: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.

提交回复
热议问题