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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:38:40+00:00 2026-06-18T23:38:40+00:00

Consider following binary tree, where nodes have two sons or are leafs with labels.

  • 0

Consider following binary tree, where nodes have two sons or are leafs with labels. This code compiles in g++ 4.7.2:

#include <memory>
using namespace std;

struct Tree {
    unique_ptr<Tree> left, right;
    char label;

    Tree(char label) : label(label) {}

    Tree(Tree && left, Tree && right) :
        left(new Tree(move(left))), 
        right(new Tree(move(right))) {}

    //~ explicit Tree(Tree && left, bool right) {}

} tree {{1, 2}, 3};

When I uncomment explicit constructor it fails to compile (if this explicit constructor is private it fails too). Is this gcc bug, or explicit constructors forbid using initializer list construction for non-explicit ones with same number of arguments?

Edit: s/implicit/non-explicit/. Sorry for confusion, I used word “implicit” for “allowing implicit conversion” and “explicit” as “marked with the keyword explicit”. I call constructors automagically generated by compiler “default”, so I didn’t notice word “implicit” will be so ambiguous.

  • 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-18T23:38:41+00:00Added an answer on June 18, 2026 at 11:38 pm

    Your question seems to assume something which is not true, and reveals a fundamental misunderstanding.

    To begin with, implicitly generated constructors are not hidden “when using initializer lists”. Their generation is simply inhibited any time you define a constructor, no matter whether you mark it as explicit or not.

    Beware though: what is usually meant by “implicit” constructor is a constructor which is implicitly (automatically) generated by the compiler when you provide none, not a constructor which lacks the explicit modifier. In the above paragraph I was talking about the former, but I am led to believe that you are thinking about the latter.

    Assuming that this is the case, it is not true that constructors which are not marked as explicit are hidden by ones that are marked as explicit in general, whether or not you are using initializer lists.

    The reason your program does not compile is that your explicit constructor happens to be a better match than the non-explicit one, because it accepts a bool as its second argument, which only requires a standard conversion to match the argument 2. On the other hand, your non-explicit constructor accepting a Tree&& requires a user-defined conversion involving the construction of a temporary Tree object, and standard conversions are preferable over user-defined conversions.

    To force the compiler to construct a Tree temporary from the argument 2 rather than converting 2 to a bool (and, therefore, invoke the non-explicit constructor), you must specify this by changing your constructor invocation into the following:

    struct Tree
    {
        ...
    } tree {{1, Tree(2)}, 3}; // Explicitly specify the second argument is to be
                              // used to create a temporary Tree object, rather
                              // than being converted to a bool
    

    Also notice, that while the same applies to the creation of the top-level tree (i.e. 3 gets converted into a bool as well and your explicit constructor is invoked again), this is not a problem in this case, because you are direct-initializing the tree object, and no implicit conversion is attempted.

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

Sidebar

Related Questions

Consider the following array, which is claimed to have represented a binary tree: [1,
Consider the following binary tree: (taken from here ) Given that leaf nodes will
Let us consider the following picture this is a so called range tree. I
Consider following case: I have base class inherited by another two. For instance we
Consider the binary tree developed in Moose::Cookbook::Basics::Recipe3 To retrieve all nodes in preorder ,
i need some help with this problem. I have a binary tree stucture which
Consider following code: Dim S1 As String = a 'this is the string in
Consider following code: My problem is: 1) I can't seem to cast the errors
consider following: 1st APPROACH: public void f3() { f2(); f1(); } and this ...
Consider following scenario: I have RESTful URL /articles that returns list of articles user

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.