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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:26:57+00:00 2026-05-30T06:26:57+00:00

I always thought that implicit constructor in C++ could only be a constructor with

  • 0

I always thought that implicit constructor in C++ could only be a constructor with only one argument. For example:

class Foo1
{
   Foo(int); // This could be an implicit constructor
};

But is the following code right:

class Foo2
{
    Foo2(int, int=0);  // Would compiler use this as an implicit constructor?
}

I can do this:

Foo1 obj;
...
obj = 5;

What about Foo2?

  • 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-30T06:26:59+00:00Added an answer on May 30, 2026 at 6:26 am

    First, any constructor can be marked explicit. How many arguments it has is irrelevant.

    With that out of the way, you just now need to understand what explicit really means. It just means that the only way that constructor can be called is when you explicitly specify the class name:

    struct foo
    {
        foo(int){}
        explicit foo(double){}
    };
    
    void bar(foo){}
    
    bar(5); // okay, calls foo(int) to construct the foo
    bar(3.14); // error, cannot call foo(double) because foo was not explicitly used
    bar(foo(3.14)); // okay, calls foo(double) to construct the foo
    

    The reason we don’t mark multiple-argument constructors explicit is because it’s useless. Given:

    struct baz
    {
        baz(int, int, int);
    };
    

    How else can you call that constructor other than saying baz anyway? (As in baz(1, 2, 3).)†

    In your example, explicit would be sensible because you could call that constructor with only one argument. What you actually do only depends on if you feel it should be implicitly convertible or not.


    †This is disregarding C++11 initializer lists. In C++11, I think you could say:

    void qaz(baz) {}
    
    qaz({1, 2, 3}); 
    

    And manage to get an implicit conversion to a multiple-argument constructor, but I don’t know enough about initializer-lists to make a meaningful comment except as a footnote.

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

Sidebar

Related Questions

I have code like this: setTimeout(foo, 600); I always thought that foo didn't take
I always thought that internal class has access to all data in its external
I always thought that *&p = p = &*p in C. I tried this
The comment to this answer got me wondering. I've always thought that C was
I always thought that a node in an execution plan can only be executed
I always thought that an if statement essentially compared it's argument similar to ==
This is a question that's been nagging me for some time. I always thought
I just read this article from Google. I always thought that closing tags is
I always thought that the benefit of linked lists was that you could add
I have always thought that the warp scheduler will execute one warp at a

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.