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

The Archive Base Latest Questions

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

With explicitly deleted member functions in C++11, is it still worthwhile to inherit from

  • 0

With explicitly deleted member functions in C++11, is it still worthwhile to inherit from a noncopyable base class?

I’m talking about the trick where you privately inherit a base class which has private or deleted copy constructor and copy assignment (e.g. boost::noncopyable).

Are the advantages put forward in this question still applicable to C++11?


I don’t get why some people claim it’s easier to make a class non-copyable in C++11.

In C++03:

private:
    MyClass(const MyClass&) {}
    MyClass& operator=(const MyClass&) {}

In C++11:

MyClass(const MyClass&) = delete;
MyClass& operator=(const MyClass&) = delete;

EDIT:

As many people have pointed out, it was a mistake to provide empty bodies (i.e. {}) for the private copy constructor and copy assignment operator, because that would allow the class itself invoke those operators without any errors. I first started out not adding the {}, but ran into some linker issues that made me add the {} for some silly reason (I don’t remeber the circumstances). I know better know. 🙂

  • 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-30T09:26:12+00:00Added an answer on May 30, 2026 at 9:26 am

    Well, this:

    private:
        MyClass(const MyClass&) {}
        MyClass& operator=(const MyClass&) {}
    

    Still technically allows MyClass to be copied by members and friends. Sure, those types and functions are theoretically under your control, but the class is still copyable. At least with boost::noncopyable and = delete, nobody can copy the class.


    I don’t get why some people claim it’s easier to make a class non-copyable in C++11.

    It’s not so much “easier” as “more easily digestible”.

    Consider this:

    class MyClass
    {
    private:
        MyClass(const MyClass&) {}
        MyClass& operator=(const MyClass&) {}
    };
    

    If you are a C++ programmer who has read an introductory text on C++, but has little exposure to idiomatic C++ (ie: a lot of C++ programmers), this is… confusing. It declares copy constructors and copy assignment operators, but they’re empty. So why declare them at all? Yes, they’re private, but that only raises more questions: why make them private?

    To understand why this prevents copying, you have to realize that by declaring them private, you make it so that non-members/friends cannot copy it. This is not immediately obvious to the novice. Nor is the error message that they will get when they try to copy it.

    Now, compare it to the C++11 version:

    class MyClass
    {
    public:
        MyClass(const MyClass&) = delete;
        MyClass& operator=(const MyClass&) = delete;
    };
    

    What does it take to understand that this class cannot be copied? Nothing more than understanding what the = delete syntax means. Any book explaining the syntax rules of C++11 will tell you exactly what that does. The effect of this code is obvious to the inexperienced C++ user.

    What’s great about this idiom is that it becomes an idiom because it is the clearest, most obvious way to say exactly what you mean.

    Even boost::noncopyable requires a bit more thought. Yes, it’s called “noncopyable”, so it is self-documenting. But if you’ve never seen it before, it raises questions. Why are you deriving from something that can’t be copied? Why do my error messages talk about boost::noncopyable‘s copy constructor? Etc. Again, understanding the idiom requires more mental effort.

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

Sidebar

Related Questions

The working draft explicitly calls out that defaulted-functions must be special member functions (eg
I know we can explicitly call the constructor of a class in C++ using
After reading some tutorials I am still unclear on some points about memory management
Why one would want to explicitly clear the a vector member variable (of on
[C++11: 12.8/7]: If the class definition does not explicitly declare a copy constructor, one
My colleague insists on explicitly specifying the namespace in code as opposed to using
I'm trying to explicitly disable the compilation of the _tkinter module when compiling Python
Do you need to explicitly create an index, or is it implicit when defining
The standard explicitly states that main has two valid (i.e., guaranteed to work) signatures;
Can I call constructor explicitly, without using new , if I already have 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.