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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:54:03+00:00 2026-05-27T17:54:03+00:00

As long as new issues are growing out of my previous question Overloaded assignment

  • 0

As long as new issues are growing out of my previous question Overloaded assignment operator causes warning about recursion, I was legitimately urged to post this as new one. I have a reference class member in my class Player and I want to implement the copy constructor and the assignment operator (=) of this class. I have to mention that the purpose is the fine working of the function vector.erase because without that it does not work properly as far as I am concerned. I use a vector: vector allPlayers; The members of the class Player are:

class Player
{

  private:
  int ID;
  int pMoney;
  int doubleIndicator;
  int squarePosition;
  Bank& bank;
  string pName;
  Square* capturedSquare;
  multimap<string, PropertySquare*> squaresColBought;
  multimap<string, House*> housesColBuilt;

}

Is it mandatory to avoid the use of reference as class member if I want to implement the assignment operator? What about the map members? How should I finally implement the assignment operator?

Another issue of utmost importance of which I am unaware is what happens to the objects pointed by pointers class members when I erase the iterator of the vector which hold the Player. Any help?

  • 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-27T17:54:04+00:00Added an answer on May 27, 2026 at 5:54 pm

    I would refrain from using a reference member when you want an assignment operator. If you use a (smart) pointer instead, you can just do

    Player &operator=(Player const &other)
    {
        bankPtr = other.bankPtr;
        // copy other members
    }
    

    In the current situation, bank = other.bank will copy the contents of other.bank instead of pointing this->bank to the contents referenced by other.bank.

    As for the multimap-typed members, they can be copied without problems, but do keep in mind that you’ll get a “deep” copy of the keys (since they’re of type string) but a “shallow” pointer copy of the values, so you end up with shared state. You might want to use shared_ptr for the values.

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

Sidebar

Related Questions

So I'm having issues overloading the assignment operator when working with templates. Basically, I'm
I am new to SmartGWT and having this issue for long time and could
I want to implement a java.util.Comparator with Long : new Comparator<Long>() { public int
Consider the following: long size = int.MaxValue; long[] huge = new long[size]; // throws
I have the Lat/Long value of New York City, NY; 40.7560540,-73.9869510 and a flat
we use super-long Hashes for the Registration of new Users in our Application. The
Iam new to c programming and needs some help. long *taskids[NUM_THREADS]; for(t=0; t<NUM_THREADS; t++)
I came to a new project which have been developed for a quite long
I'm new to Android programming. I spent a long time trying to look for
(Long time reader of SO, first time asking a q. I'm quite new to

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.