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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:02:41+00:00 2026-06-03T06:02:41+00:00

I declare a class’s copy-ctor and operator= private to make its objects un-copyable, and

  • 0

I declare a class’s copy-ctor and operator= private to make its objects un-copyable, and don’t provide definitions for them both. So if the class’s friends invokes copying behavior on these objects, a link-time error would occur, right?

class A
{
    public:
        ...

    private:
        A(const &a);
        A& operator=(const &a);  //just declarations, no definitions
};

But in order to move the error from link-time to compile-time, I learned from a book that I can do this:

class UnCopyable
{
    public:
        ...

    private:
        Uncopyable(const &u);
        Uncopyable& operator=(const &u);  //also no definitions
};

then make A inherit Uncopyable,

class A: private Uncopyable
{
    ...
};

And it says in the book, if someone invokes copying on A, then A should call Uncopyable‘s copying counterparts first, but Uncopyable‘s copy-ctor and operator= are private, so this will fail and error will rise, which occur in compile-time.

My question is why would that occur in compile-time?

  • 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-03T06:02:43+00:00Added an answer on June 3, 2026 at 6:02 am

    Because violations of the semantics of the language are compile-time errors, whereas link-time errors are errors that result from a function being declared but the linker cannot find a definition for it.

    In other words, a linker error means your program is a valid C++ program and has gotten to the linking stage where the linker is just patching up references to functions in other compilation units (since the compiler only considers one compilation unit at a time) but it has searched everywhere and can’t find a definition. A compile-time error means your program violates the rules of C++ somehow.

    However, you’re a little incorrect in your assumption. Making the operator= private will cause a compile time error for people who try to assign those objects. The only time you’ll get a linker error is when a function that has access to that class’s private functions (e.g. a friend function or member function) then you’ll get a linker error.

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

Sidebar

Related Questions

// declare a class with private variable int * _a // declare a function
I've noticed that some generated classes only declare class properties/variables via @property, and don't
// stock.h #ifndef STOCK_H #define STOCK_H // declare Stock Class class Stock { private:
Maybe this is obvious, but I don't know how to declare class properties in
If I declare class as abstract with no abstract methods declared in it, will
How would I declare a class that has a method/message that takes a selector,
I want my PHP extension to declare a class equivalent to the following PHP:
I have built a class in PHP and I must declare a class variable
I am trying to forward declare a class that is derived from a template
I'm getting this error whenever I attempt to declare a class: Parse error: syntax

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.