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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:51:39+00:00 2026-05-19T11:51:39+00:00

setting aside the fact that I use getter/setter where the more experienced C++-programmer won’t

  • 0

setting aside the fact that I use getter/setter where the more experienced C++-programmer won’t make use of them I have a problem with the following code:

#include "Player.h"

class Entity 
{
public:
    Entity::Entity(Player& _owner) 
        : owner(_owner) { }
    Player &get_owner() { return this->owner; }
    void set_owner(Player &_owner) { this->owner = _owner; }

private:
    Player &owner;
};

This gives me a C2582 saying the ‘operator =’ is unavailable for Player in the set_owner function. My Player class looks like this:

class Layer;
class Cell;

class Player
{
public:
    Player();
    void credit_to_balance(const long &_amount);
    ..more getter/setter..
private:
    long balance;
    Layer &current_layer;
    Cell &current_cell;
};

Until now I thought my default constructor/destructor and = operator would !always! be constructed by the compiler if I haven’t done it myself (and they are used throughout the program). Apparently this isn’t the case this time as other classes would also complain about removing the manually inserted default c’tor from Player. I even tried to write a small example program that does exactly the same (even with forward declaration and members that are references) and it worked.

And in my opinion it definitely should, because it would only copy some references and an intrinsic type. This is why I did not yet try to write my own = operator as I see no difficulties for the compiler to do that for me. For me it would lead into the problem of having in mind to update it each time I’m introducing new members to my class.

So much for my thoughts on this problem. I hope you guys can show me what I’m missing 🙂
Thanks in advance!

  • 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-19T11:51:40+00:00Added an answer on May 19, 2026 at 11:51 am

    You cannot “reseat” a reference, not even a class member which is a reference. this->owner = _owner; is not going to change what object the member refers to, it’s attempting to modify the object this->owner always has referred to and always will.

    If you need your class to change what other object(s) it refers to, use pointer members instead of reference members. You can keep the same public interface and just use & and * operators to “convert”.

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

Sidebar

Related Questions

i have a few problems setting up a layout with horizontal sections that should
After setting up a replication on my server (SQL2005) I have noticed that default
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work
When setting up foreign keys in SQL Server, under what circumstances should you have
The context is that I have an on off-the-shelf CMS which I want to
Setting aside the heap's capacity, are there ways to go beyond Integer.MAX_VALUE constraints in
I have a desktop application written in Ruby that is using GTK2. It's just
Setting up paperclip to use S3 on my local dev system was a snap.
After setting up a mysqli object in php, i want to make to insert
I have a new web app that is packaged as a WAR as part

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.