Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:49:28+00:00 2026-06-01T04:49:28+00:00

Can anyone tell me the cause of error ? Error is C:\web\template1.cpp||In function ‘int

  • 0

Can anyone tell me the cause of error ?

Error is

C:\web\template1.cpp||In function 'int main()':|
C:\web\template1.cpp|23|error: call of overloaded 'swap(int&, int&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = int]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&, _Tp&) [with _Tp = int]|
C:\web\template1.cpp|24|error: call of overloaded 'swap(double&, double&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = double]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&, _Tp&) [with _Tp = double]|
C:\web\template1.cpp|25|error: call of overloaded 'swap(char&, char&)' is ambiguous|
C:\web\template1.cpp|6|note: candidates are: void swap(X&, X&) [with X = char]|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\move.h|76|note:                 void std::swap(_Tp&, _Tp&) [with _Tp = char]|
||=== Build finished: 3 errors, 0 warnings ===|

#include <iostream>

using namespace std;

template <typename X>
void swap(X &a, X &b)
{
    X temp = a;
    a = b;
    b = temp;
}

int main()
{
    int i=10, j=20;
    double x=10.1, y=23.3;
    char a='x', b='z';

    cout<<"i="<<i<<"\tj="<<j<<endl;
    cout<<"x="<<x<<"\ty="<<y<<endl;
    cout<<"a="<<a<<"\tb="<<b<<endl;

    swap(i,j);
    swap(x,y);
    swap(a,b);

    cout<<"i="<<i<<"\tj="<<j<<endl;
    cout<<"x="<<x<<"\ty="<<y<<endl;
    cout<<"a="<<a<<"\tb="<<b<<endl;

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:49:30+00:00Added an answer on June 1, 2026 at 4:49 am

    Your swap conflicts with std::swap. Remove using namespace std; above and correct the rest code from std namespace.

    std::cout<<"i="<<i<<"\tj="<<j<<std::endl;
    std::cout<<"x="<<x<<"\ty="<<y<<std::endl;
    std::cout<<"a="<<a<<"\tb="<<b<<std::endl;
    

    Also it’s worth reading Why is "using namespace std" considered bad practice?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell by looking at this style will cause a combobox with it
Can anyone please tell me why I keep getting an error right before the
Can anyone tell me where does following HTTP error message come from: Due to
Can anyone tell me why I am getting error when I am validating even
Can anyone tell me whether Helvetica is a browser base font? If so, it
Can anyone tell me why ActionScript 3, a statically typed language, doesn't have generics?
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me how to write and run msbuild by using VS 2005?
Can anyone tell me how to do runtime debugging on shared libraries? I need
can anyone tell me what is the best way to do something like, from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.