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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:42:07+00:00 2026-05-26T23:42:07+00:00

Using gcc version 4.4.3 as follows: gcc -g -x c++ -lstdc++ -std=c++98 -o ./main

  • 0

Using gcc version 4.4.3 as follows:

gcc -g -x c++ -lstdc++ -std=c++98 -o ./main ./main.cpp

this code in main.cpp compiles fine:

#include <iostream>

struct A
{
    A()
    : m_flag(false)
    {
    }

    const bool m_flag;
};

static A aa = A();

int main(int argc, char* argv[])
{
    A a;

    // Not static = copy OK
    A b( a );
    A c = b;
    A d = A();

    // Static = copy not OK
    // aa = A();
}

But if I uncomment aa = A(); I get:

./main.cpp: In member function 'A& A::operator=(const A&)':
./main.cpp:4: error: non-static const member 'const bool A::m_flag', can't use default assignment operator
./main.cpp: In function 'int main(int, char**)':
./main.cpp:24: note: synthesized method 'A& A::operator=(const A&)' first required here 

Why does the default copy construction and copy assignment work for copies on the stack but not when replacing the non-const static with a copy?

  • 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-26T23:42:08+00:00Added an answer on May 26, 2026 at 11:42 pm

    The problem is this line:

     const bool m_flag;
     ...
     aa = A();  // invokes 'A::operator =(const A&)`
    

    which invokes default operator =. Modifying const member is a trivial error.

    A b( a );   // all invoke `A::A(const A&)`
    A c = b;  
    A d = A(); 
    

    invokes default copy constructor (not operator = as you assume), where m_flag is assigned a new value at the initialization itself.

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

Sidebar

Related Questions

My code is as follows: #include <cmath> #include <iostream> float foo(float f) { std::cout
#include<iostream> using namespace std; int main() { int hash, opp, i, j, c =
Here is some code I wrote (using GCC's __restrict__ extension to C++): #include <iostream>
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
#include <iostream> #include <vector> using namespace std; class Parent { public: Parent(); void method();
I was using mysql++ library and compiling with GCC 3.3.4. That GCC version had
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
I'm using GCC; __FILE__ returns the current source file's entire path and name: /path/to/file.cpp
I am using gcc on linux. I was previously using the following code :
The following code int _main() {return 0;} Compiled using the command: gcc -s -nostdlib

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.