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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:38:16+00:00 2026-05-27T09:38:16+00:00

Could anyone help me understand why the below code doesn’t compile (VS2010) when the

  • 0

Could anyone help me understand why the below code doesn’t compile (VS2010) when the getters are const ?

Here’s the test code:

#include <boost/system/error_code.hpp>

class socket {
public:

    // setter - throw exception version
void non_blocking(bool mode)
    {
        // ...
    }

    // getter - error code version      
    bool non_blocking(boost::system::error_code& ec) const
    {
        // ...
    }

    // setter - error code version
void non_blocking(bool mode, boost::system::error_code& ec)
    {
        // ...
    }

    // getter - throw exception version    
    bool non_blocking() const
    {
        // ...
    }
};

int main()
{
    socket s;
    boost::system::error_code ec;
    bool result = s.non_blocking(ec);

    return 0;
}

I know that boost::system::error_code is convertible to bool but can’t understand why the const cause the ambiguity. Here’s the error message from VS2010:

1>c:\projects\pcap++\trunk\main.cpp(145): error C2666: 'socket::non_blocking' : 2 overloads have similar conversions
1>          c:\projects\pcap++\trunk\main.cpp(134): could be 'bool socket::non_blocking(boost::system::error_code &) const'
1>          c:\projects\pcap++\trunk\main.cpp(129): or       'void socket::non_blocking(bool)'
1>          while trying to match the argument list '(boost::system::error_code)'
1>          note: qualification adjustment (const/volatile) may be causing the ambiguity
  • 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-27T09:38:17+00:00Added an answer on May 27, 2026 at 9:38 am

    For the purpose of overload resolution, the parameter list of the two overloads are class socket &, bool and const class socket &, boost::system::error_code &.

    The calling parameters are class socket &, boost::system::error_code &

    To match the first overload, the following conversion is needed:

    1.
    class socket &              -> no conversion
    bool                        -> user defined conversion
    2.
    class socket &              -> qualification conversion
    boost::system::error_code & -> no conversion
    

    In C++0x 13.3.3p1 :

    Define ICSi(F) as follows:

    — if F is a static member function, ICS1(F) is defined such that
    ICS1(F) is neither better nor worse than ICS1(G) for any function G,
    and, symmetrically, ICS1(G) is neither better nor worse than
    ICS1(F); otherwise,

    — let ICSi(F) denote the implicit conversion sequence that converts
    the i-th argument in the list to the type of the i-th parameter of
    viable function F. 13.3.3.1 defines the implicit conversion sequences
    and
    13.3.3.2 defines what it means for one implicit conversion sequence to be a better conversion sequence or worse conversion sequence than
    another.

    Given these definitions, a viable function F1 is defined to be a
    better function than another viable function F2 if for all arguments
    i, ICSi(F1) is not a worse conversion sequence than ICSi(F2)
    , and then

    ….

    From this, we can see the neither of the match of the two overloads fits this requirement. For the one function, one conversion sequence is better and one conversion is worse than the corresponding conversion sequence of the other function, so the viable function cannot be determined.

    If the second overload is not const, then the conversion sequence for the second overload does not need any conversion (both are identical), so this is better than the other overload, thus no ambiguity.

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

Sidebar

Related Questions

Could anyone help me to understand following line of code: sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price; I
Could any one help me understand the below code. Please help me how it
I wonder if anyone can help me to understand where I could be going
Could anyone help me understand why the following query works fine in SQL 2000
I was wondering if anyone could help me understand if what I am doing
So I was wondering if anyone could help me understand how the jQuery 'class'
Ok so could anyone please help me out with the VB for auto entering
I need to get substed drive letter in Perl. Could anyone kindly help me?
I wonder if anyone could help me with a problem I've been having. I
OK, if anyone could help me with this I'd be much appreciative. If you

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.