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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:32:30+00:00 2026-05-24T12:32:30+00:00

Here is a piece of code: class GameBoard { public: GameBoard() { cout<<Gameboard()\n; }

  • 0

Here is a piece of code:

class GameBoard
{
    public:
    GameBoard() { cout<<"Gameboard()\n"; }
    GameBoard(const GameBoard&)
    {
        cout<<"GameBoard(const GameBoard&)\n";
    }

    GameBoard& operator=(const GameBoard&)
    {
        cout<<"GameBoard& operator=(const GameBoard&)\n";
        return *this;
    }
    ~GameBoard() { cout<<"~GameBoard()\n";};
};    

class Game
{
    GameBoard gb;
    public:
    Game(){ cout<<"Game()\n"; }
    Game(const Game&g):gb(g.gb)
    {
        cout<<"Game(const Game&g)\n";
    }
    Game(int) {cout<<"Game(int)\n"; }
    Game& operator=(const Game& g)
    {
        gb=g.gb;
        cout<<"Game::operator=()\n";
        return *this;
    }
    class Other
    {
        public:
        Other(){cout<<"Game::Other()\n";}
    };
    operator Other() const
    {
        cout<<"Game::Operator Other()\n";
        return Other();
    }
    ~Game() {cout<<"~Game()\n";}
};  

class Chess: public Game {};

void f(Game::Other) {}

class Checkers : public Game
{
    public:
    Checkers() {cout<<"Checkers()\n";}
    Checkers(const Checkers& c) : Game(c)
    {
        cout<<"Checkers(const Checkers& c)\n";
    }
    Checkers operator=(const Checkers& c)
    {
        Game::operator=(c);
        cout<<"Checkers operator=(const Checkers& c)\n";
        return *this;
    }
}; 

int main()
{
    Chess d1;
    Chess d2(d1);
    d1=d2;
    f(d1);
    Game::Other go;
    Checkers c1,c2(c1);
    c1=c2;
}

Here is the output

Gameboard()                        //Constructing d1
Game()
GameBoard(const GameBoard&)
Game(const Game&g)                 //d2(d1)
GameBoard& operator=(const GameBoard&)
Game::operator=()                  //d1=d2
Game::Operator Other()             //f(d1)
Game::Other()
Game::Other()                      //go             
Gameboard()                        //c1
Game()
Checkers()
GameBoard(const GameBoard&)        //c2(c1)
Game(const Game&g)
Checkers(const Checkers& c)
GameBoard& operator=(const GameBoard&)    //c1=c2
Game::operator=()
Checkers operator=(const Checkers& c)
GameBoard(const GameBoard&)               ?
Game(const Game&g)                        ?
Checkers(const Checkers& c)               ?
~Game()
~GameBoard()
~Game()
~GameBoard()
~Game()
~GameBoard()
~Game()
~GameBoard()
~Game()
~GameBoard()

My question is why is the last set of copy constructors being called?

  • 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-24T12:32:31+00:00Added an answer on May 24, 2026 at 12:32 pm

    Because your assignment operator for Checkers return a value instead of a reference as it is customary.

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

Sidebar

Related Questions

Here is a simple piece of code: import java.io.*; public class Read { public
Here is a piece of code: public class Schema { public Schema(List<CountryParticipantsStages> places) {
I have following piece of code: class Test{ private: int id; public: Test(int v):id(v)
Allright, here it goes a good piece of bad code: public class Log :
Here is a piece of code: class Class { static constexpr int getBug(); };
Here is a piece of code: private class myClass { public static void Main()
Here's a piece of code from the xss_clean method of the Input_Core class of
I've been here and accordingly found out that this piece of code here var
Let's say we have the following piece of code: public class Event { }
I found an article with an interesting piece of code: public class Employee {

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.