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

  • Home
  • SEARCH
  • 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 8437781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:31:46+00:00 2026-06-10T07:31:46+00:00

For some reason , the compiler cannot generate the operator= for this class because

  • 0

For some reason , the compiler cannot generate the operator= for this class because of the initialization of the const field _constFoo, I just wanna know why. Using VS2010.

class Foo {
public:
    Foo(int f) : _constFoo(f) { }
    int getFoo() const { return _constFoo; }
    //void operator=(const Foo &f) { memcpy(this, &f, sizeof(Foo)); }
private:
    const int _constFoo;
};

int main(int argc, char *argv[])
{
    Foo f(5);
    cout << f.getFoo() << endl;
    f = Foo(6); //error C2582: 'operator =' function is unavailable in 'Foo'
    cout << f.getFoo() << endl;
}
  • 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-10T07:31:47+00:00Added an answer on June 10, 2026 at 7:31 am

    The standard disallows it:

    C++03 12.8. Copying objects

    12) […] A program is ill-formed if the class for which a copy
    assignment operator is implicitly defined has:

    • a non-static data member of const type, or
    • a non-static data member of reference type, or
    • a non-static data member of class type (or array thereof) with an inaccessible copy assignment operator, or
    • a base class with an inaccessible copy assignment operator.

    […]

    emphasis mine.

    So your program is ill-formed. By not defining your own assignment operator, the compiler attempts to implicitly define one.

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

Sidebar

Related Questions

I declared a global shift operator but for some reason the compiler cannot deduct
For some strange reason g++ (versions 4.5.0 and 4.5.2) cannot compile this code: bool
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
for some reason my play eclipse app cannot run a bootstrap job and throws
There are some topics on Stack Overflow on the compiler error Cannot refer to
For some reason, I should use gcc to compile a C file, then link
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason I can't detect I can't set a z index for any
For some reason there's a variable called d that is defined immediately after I

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.