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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:47:16+00:00 2026-05-28T14:47:16+00:00

In short: is there some way I can modify a class definition such that

  • 0

In short: is there some way I can modify a class definition such that it fails to compile at the point of use of a copy constructor no matter where it’s used?

I have a very large project and was cleaning up some class definitions. There’s a class that I explicitly don’t want to use copy constructors on (let’s ignore why that is for the sake of this discussion), and in the interest of safety, I figured I’d just define the copy constructor as private and not actually implement it… that way it would throw a compile error if I tried to use it anywhere. Lo and behold, it compiles fine, but I have a linker error… the copy constructor implementation is not found! Presumably that means it’s in use somewhere, but I’m unable to find where it’s being used. This is Visual Studio 2010 by the way. So my question is, is there some way I can modify the class definition such that it fails to compile at the point of use?

class Sample {
private:
    // not implemented
    Sample( const Sample& rhs );
    Sample& operator=( const Sample& rhs );
public:
    // implemented
    Sample();
...
};

Sample *samp1 = new Sample;
Sample *samp2 = new Sample( *samp1 ); // <<-- inaccessible here!  this works

Presumably since I’m not hitting a compile error, but am hitting the linker error, that it means the class itself (or a friend) is doing the copy-constructed create (since that’s all that would have access to the private constructor), but I sure can’t find it!

  • 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-28T14:47:16+00:00Added an answer on May 28, 2026 at 2:47 pm

    in C++11 you can change the definition to

    class Sample {
    private:
        // not implemented
        Sample( const Sample& rhs ) = delete;
        Sample& operator=( const Sample& rhs ) = delete;
    public:
        // implemented
        Sample();
    ...
    };
    

    prior to C++11 this is usually done by inheritting from a class that declares a private copy constructor such as boost::NonCopyAble (you can simply copy this class, it’s only a few lines). In this case your class (or any friends or children) also cannot access the copy constructor and it will generate a compile-time error.

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

Sidebar

Related Questions

Short version: Can a COM class modify its own virtual table entries at runtime?
(using Ruby on Rails and ActiveRecord) In short: Is there some way how a
Is there a way to run some sort of code analysis to find code
Is there any standard way of implementing some sort of a write-through buffer for
Is there a web service of some sort (or any other way) to pull
Is there a way to start an instance of eclipse, passing it some sort
Is there some sort of C# directive to use when using a development machine
I've got some (badly written) legacy code that I have to modify but I'm
I was wondering if there is some standardized way of getting type sizes in
Is there a typedef equivalent in C#, or someway to get some sort of

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.