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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:30:37+00:00 2026-05-28T03:30:37+00:00

[C++11: 12.8/7]: If the class definition does not explicitly declare a copy constructor, one

  • 0

[C++11: 12.8/7]: If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor. Thus, for the class definition

struct X {
   X(const X&, int);
};

a copy constructor is implicitly-declared. If the user-declared constructor is later defined as

X::X(const X& x, int i =0) { /* ... */ }

then any use of X’s copy constructor is ill-formed because of the ambiguity; no diagnostic is required.

This doesn’t make a lot of sense to me.

How does the code sample introduced by “thus” have anything to do with the “latter” case that I highlighted in italics?

My understanding so far is that:

  • If the class definition does not explicitly declare a copy constructor, and
  • the class definition does not declare a move constructor or move assignment operator, and
  • the class has a use-declared copy assignment operator or a user-declared destructor, then
  • the implicitly-defined copy constructor is defined as defaulted, and this is deprecated.

This seems odd in itself, that a standard-mandated behaviour is — in the same breath — deprecated. Does this mean that having a class that satisfies those three conditions is deprecated?

And what does the code sample have to do with it? That constructor is not a copy constructor, move constructor, move assignment operator, copy assignment operator or a user-declared destructor; it’s just a user-declared constructor, no? Where’s this “ambiguity”?

Could someone decode this passage for me?

  • 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-28T03:30:37+00:00Added an answer on May 28, 2026 at 3:30 am

    Does this mean that having a class that satisfies those three conditions is deprecated?

    Yes; if you have a use-declared copy-assignment operator or destructor, you should also declare a copy constructor. It’s basically just saying that your class should follow the Rule of Three (or Five, or whatever it’s called in C++11).

    This seems odd in itself, that a standard-mandated behaviour is — in the same breath — deprecated.

    The behaviour is mandated by the standard because that was the behaviour in C++03 – changing it would break legacy code. Just as the standard defines the behaviour of (for example) dynamic exception specifications, and also deprecates them.

    How does the code sample introduced by “thus” have anything to do with the “latter” case that I highlighted in italics?

    It doesn’t have anything to do with the “latter” case.

    It is an illustration of a potential problem caused by the normal behaviour defined by the clause: there will be a conflict between an implicitly-declared copy constructor, and a user-declared constructor with default arguments such that it can be called like a copy constructor.

    Where’s this “ambiguity”?

    Consider the code:

    X x1;  // assume there's also a default constructor
    X x2(x);
    

    Should x2 be initialised with the user-declared constructor (with the second argument taking its default value), or the implicitly-declared copy constructor? Both are an equally good match for the usage. That is the ambiguity.

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

Sidebar

Related Questions

Consider the case of class which does not have a destructor and constructor explicitly
I'm defining an iterator type that does not store its current value explicitly. Instead,
Say I have a class definition: class CustomClass { int member; }; Why is
A random class definition: class ABC: x = 6 Setting some values, first for
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
Session contains objects whose class definition isn\'t available. Remember to require the classes for
Consider the following class definition: class StrToTokens { StrToTokens(const char* str, const char* delimiters
I have the following class definition: template<typename QueueItemT> class QueueBC { protected: QueueBC() {}
Given a simple C# class definition like: [System.Windows.Markup.ContentProperty(PropertyOne)] public class SimpleBase { public string
Let's have the following class definition: CThread::CThread () { this->hThread = NULL; this->hThreadId =

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.