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

The Archive Base Latest Questions

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

While developing a game I have designed a class that in normal operation has

  • 0

While developing a game I have designed a class that in normal operation has a const member variable like so:

class Foo {
    /* ... */
protected:
    const boost::unordered_map<short, short> m_map;
};

However, in the accompanying game editor I would like to reuse the Foo class, but provide a way to edit this const member as it is used in rendering the game (and I would like to reuse the renderer for the editor). As such, I was planning on subclassing the Foo class in order to provide methods for changing various properties as well as serializing the data for saving the editor data. I’m wondering if there’s an elegant way to do this while keeping the member as const or if there is a better design?

The options I have come up with so far are:

  • Remove the const keyword and simply provide no public interface for changing the variable
  • Change the renderer to use an interface and implement it separately in both Foo and the editor version of Foo
  • Reimplement the public interface of Foo to use a new, mutable map for the editor version of Foo
  • Something else entirely?

At first hand the interface path seems like the cleanest from a language perspective, but leads to an interface (abstract base class) for each and every class involved which is a decent effort. Suggestions and ideas welcome. (Note: I had a hard time coming up with a descriptive title; suggestions welcome for that also.)

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

    If making your variable non-const and protected feels too intrusive perhaps you can have a design where the variable is non-const and private, and provide protected member functions to manipulate it with whatever constraints you had in mind when you made the variable const in the first place.

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

Sidebar

Related Questions

While developing my app I have come to realize that the majority of my
In a multiplayer game I'm developing, we have a few values that are floating
While developing my ASP.NET MVC, I have started to see the need for a
After working for a while developing games, I've been exposed to both variable frame
While developing a joomla plugin, if my plugin folder looks like so: /install.xml /mainPg.php
Been developing a game for a while, and currently re working the GUI, or
I've been developing Web applications for a while now and have dipped my toe
I am developing a game on Iphone using cocos2d. I have a CClayer containing
Let's assume I am in charge of developing a Scrabble game, being that one
I am developing an action multiplayer game with the help of the System.Net.Sockets.UdpClient class.

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.