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

  • Home
  • SEARCH
  • 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 219203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:49:22+00:00 2026-05-11T18:49:22+00:00

Several comments on a recent answer of mine, What other useful casts can be

  • 0

Several comments on a recent answer of mine, What other useful casts can be used in C++, suggest that my understanding of C++ conversions is faulty. Just to clarify the issue, consider the following code:

#include <string>

struct A {
    A( const std::string & s ) {}
};

void func( const A & a ) {
}

int main() {
    func( "one" );                  // error
    func( A("two") );           // ok
    func( std::string("three") );   // ok
}

My assertion was that the the first function call is an error, becauuse there is no conversion from a const char * to an A. There is a conversion from a string to an A, but using this would involve more than one conversion. My understanding is that this is not allowed, and this seems to be confirmed by g++ 4.4.0 & Comeau compilers. With Comeau, I get the following error:

"ComeauTest.c", line 11: error: no suitable constructor exists 
      to convert from "const char [4]" to "A"
      func( "one" );                    // error

If you can point out, where I am wrong, either here or in the original answer, preferably with reference to the C++ Standard, please do so.

And the answer from the C++ standard seems to be:

At most one user-defined conversion
(constructor or conversion function)
is implicitly applied to a single value.

Thanks to Abhay for providing the quote.

  • 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-11T18:49:22+00:00Added an answer on May 11, 2026 at 6:49 pm

    I think the answer from sharptooth is precise. The C++ Standard (SC22-N-4411.pdf) section 12.3.4 titled ‘Conversions’ makes it clear that only one implicit user-defined conversion is allowed.

    1 Type conversions of class objects can be specified by
    constructors and by conversion
    functions. These
    conversions are called user-defined conversions and are used
    for implicit type conversions (Clause
    4), for
    initialization (8.5), and for explicit type conversions (5.4,
    5.2.9).

    2 User-defined conversions are applied only where they are
    unambiguous (10.2, 12.3.2).
    Conversions obey the
    access control rules (Clause 11). Access control is applied after
    ambiguity resolution (3.4).

    3 [ Note: See 13.3 for a discussion of the use of conversions
    in function calls as well as examples
    below. —end
    note ]

    4 At most one user-defined conversion (constructor or conversion
    function) is implicitly applied to a
    single
    value.

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

Sidebar

Related Questions

Is there a built-in command or tool that can reflow C# comments in Visual
I can't seem to find anything that comments on the behaviour I am having
I have an entry that could have several comments associated with that entry. If
I have several questions so I'll put numbers in comments so that the questioned
I'm working on a social networking system that will have comments coming from several
I have read several comments here that dBase is a dead system and no
I've read several comments here and elsewhere suggesting that Erlang's process dictionary was a
In the following example, the author made several comments on the implicit conversion. Can
**EDIT: There are several options below that would work. Please vote/comment according to your
Several months ago I learned from an answer on Stack Overflow how to perform

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.