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

The Archive Base Latest Questions

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

Based on issues growing out of previous questions: vector::erase with pointer member , Remove

  • 0

Based on issues growing out of previous questions: vector::erase with pointer member, Remove elements of a vector inside the loop, I still need some help on vector.erase function. I was indicated to implement a copy constructor to make the erase function work on a vector, something that is also mentioned in another question. It is essential to implement a function operator in my relevant class. On doing this I get another error on creating the copy constructor and I cannot find the reason for long. The error is “Player::Player(const Player& otherPlayer) does not provide an initiallizer for:” . What am I doing wrong? Take into consideration that Player contains as class members map, pointers and a reference (bank is a reference) . Is a simple assignment adequate for the initialization?

What should I do?

class Player
{
public:
Player(int,int,string, Bank&);
Player(const Player&); 
Player& operator = (const Player& rhs); 


Player::Player(const Player& otherPlayer)
{
ID = otherPlayer.ID;  
pName = otherPlayer.pName;
pMoney = otherPlayer.pMoney;
doubleIndicator = otherPlayer.doubleIndicator;
position = otherPlayer.position;
bank = otherPlayer.bank;
colBought = otherPlayer.colBought;
housesColBuilt = otherPlayer.housesColBuilt;

}

Update:
I get a warning at the point of implementantion of the operator= as:”returning address of a local variable or temporary”. Does this evoke a real problem? If so, how could I modify it to get over this?

Player& Player::operator=(const Player& rhs)
{
return Player(rhs);
}

In this way, I still receive a warning that the recursive function will cause stack overflow:

Player& Player::operator=(const Player& rhs)
{
*this = Player(rhs);
return *this;
}

Any hint?

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

    You must initialize references that are members of a class with a member initializer in the constructor:

    Player::Player(const Player& otherPlayer) : 
        bank(otherPlayer.bank)
    {
        //...
    }
    

    This is needed because otherwise the reference would be uninitialized, which is not allowed.

    Note that the assignment bank = otherPlayer.bank; does something different: It assigns the object that is referenced, rather than sets the reference itself.

    It’s also good style to initialize other members (even if they aren’t references) in the same way, as it can lead to more optimal code (otherwise members could be default-constructed before being assigned).

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

Sidebar

Related Questions

Based on my previous question here my new concern is how do I unit
Back with another web based issue. When a control issues a postback to the
Based on the great answer at multi-step registration process issues in asp.net mvc (splitted
SOLUTION Refer to my answer below: issues with form/iframe based file upload in Opera
Am looking for tools to detect Memory Leaks, File open issues in Java based
I'm working on a touch based game, and I'm having issues drawing a path
I've done some web-based projects, and most of the difficulties I've met with (questions,
I'm having several issues based around reading and writing an NSArray to and from
I'm working on a bit-based B/W/Greyscale Pre-Compiled font format, and was having issues with
Two issues / questions: 1) In many of the log4j threads / forums /

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.