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 7165065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:10:44+00:00 2026-05-28T14:10:44+00:00

I am constantly getting an ambiguous overload error no matter what I do ….

  • 0

I am constantly getting an ambiguous overload error no matter what I do ….
here’s my code

COMPLEX.cpp code

template<class C> class complex
{  
    C real,imag;

    public:

    //constructors
    complex(C real=0,C imag=0)
    {
        complex::real=real;
        complex::imag=imag;
    }

    complex(const complex& cmplx)
    {
        real=cmplx.real;
        imag=cmplx.imag;
    }

    //functions available
    complex<C> operator+(const complex&);
    complex<C> operator+(double);
    void operator=(const complex&);

    //friend functions available
    template<class F> friend complex<F> operator+(double,const complex<F>&);
    template<class F> friend istream& operator>>(istream&,const complex<F>&);
    template<class F> friend ostream& operator<<(ostream&,const complex<F>&);
 };

OPERATOR>> implementation

template<class F> istream& operator>>(istream& cin,const complex<F>& cmplx)
{
    cout<<"\nenter real part followed by imaginary part : ";

    cin>>cmplx.real>>cmplx.imag;

    return cin;
}

MAIN method

int main(void)
{
    complex<int> C1;
    complex<int> C2;
    complex<int> C3;

    cin>>C1>>C2>>C3;

    cout<<C1<<C2<<C3;

    C1=C1+3;
    C2=2+C2;
    C3=C1+C2;

    cout<<C1<<C2<<C3;

    complex<int> C4(C3);

    cout<<C4;

    return 0;   
}

COMPILER ERROR

COMPLEX.cpp: In function ‘std::istream& operator>>(std::istream&, const complex<C>&) [with F = int, std::istream = std::basic_istream<char>]’:

COMPLEX.cpp:91:7:   instantiated from here

COMPLEX.cpp:75:2: error: ambiguous overload for ‘operator>>’ in ‘cin >> cmplx.complex<int>::real’

COMPLEX.cpp:75:2: note: candidates are:
/usr/include/c++/4.6/istream:122:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>] <near match>

/usr/include/c++/4.6/istream:122:7: note:   no known conversion for argument 1 from ‘const int’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&) {aka std::basic_istream<char>& (*)(std::basic_istream<char>&)}’

/usr/include/c++/4.6/istream:126:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>, std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>] <near match>

/usr/include/c++/4.6/istream:126:7: note:   no known conversion for argument 1 from ‘const int’ to ‘std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’

/usr/include/c++/4.6/istream:133:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>] <near match>

/usr/include/c++/4.6/istream:133:7: note:   no known conversion for argument 1 from ‘const int’ to ‘std::ios_base& (*)(std::ios_base&)’

/usr/include/c++/4.6/istream:241:7: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_istream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>] <near match>

/usr/include/c++/4.6/istream:241:7: note:   no known conversion for argument 1 from ‘const int’ to ‘std::basic_istream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’

before this I wrote a MATRIX.cpp and istream overload works fine there even though its nearly the same as here….

  • 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-05-28T14:10:45+00:00Added an answer on May 28, 2026 at 2:10 pm
    template<class F> istream& operator>>(istream& cin,const complex<F>& cmplx)
                                                       ^^^^^
    

    That const is a problem – you need to change cmplx here, it can’t be const. That’s what the compiler is complaining about: cmplx.real is const int inside that function.

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

Sidebar

Related Questions

I am trying to install SciPy following these instructions: http://www.scipy.org/Download And constantly getting error
I'm constantly getting an error on the TFS2010 build server, due to an inexistent
i am writing a kohana controller, and i am constantly getting a weired error,
I am constantly getting the EXC_BAD_ACCESS error in multiple places but always on the
I'm trying to get smartgit running on Ubuntu, and I'm constantly getting this error:
I'm getting a 401 constantly without further explanation of what the error is when
Every now and then I start getting this error in the debugger constantly. Sometimes
Just looking at ways of getting named constants in python. class constant_list: (A_CONSTANT, B_CONSTANT,
I am getting an error message expression must have constant value when initializing an
I constantly find myself writing similar code like the example below: if (object[Object Name]

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.