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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:22:57+00:00 2026-06-17T21:22:57+00:00

Well for example I have a map class which has some members: sizeX, sizeY,

  • 0

Well for example I have a map class which has some members: sizeX, sizeY, vector of tiles, name etc.

There are 2 basic approaches of managing its variables which are accessed from outside:

  • encapsulation, but it adds a lot of code and more typing (setX() and getX() const functions)
  • have the variables which are often accessed from outside as public members and keep it easy

I like neither of these. I came up with an idea: a class member, which from outside acts as const (so you can access it easily object.member but it’s safe) and inside the class it is non-const. However, as far as I know c++ lacks it. The only (ugly) workaround I know is to have everything const and use const cast inside class functions.

Is there better approach for this in C++ 11? Is there a keyword for it?

  • 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-06-17T21:22:58+00:00Added an answer on June 17, 2026 at 9:22 pm

    A simple workaround to just reduce slightly the amount of typing:

    #define MEMBER(T,x) \
      private: T x##_; \
      public: T const& x () const { return x##_; }
    
    struct A {
      MEMBER(int,x)
      MEMBER(double,y)
    };
    

    then you can use x_ and y_ inside the class and x() and y() outside.

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

Sidebar

Related Questions

I have a websites www.example.com which is a druapal 6 site. Works well, never
I have spatial search working well with SOLR 3.2 Example : ?q=*&fq={!geofilt pt=48.86761919303129,2.3527903735351856 sfield=coordinates
I have seen the example here . All well and good and I understand
I have a picture box. This picturebox is used for map. Map has elemenst
I have a custom class called Device which implements the MKAnnotation protocol. In the
I have a query that works well but has one problem, it displays other
Well, I got my HexString (PacketS) for example 70340A0100000000000000 I want to split every
I'm just starting with The Well-Grounded Rubyist, and they gave the following example: print
Well, my website can not redirect to https://www.facebook.com/QuaFootSpa from http://quafootspa.com/ I have tried redirection
well i have a configuration like this in the components part of my config

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.