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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:46:54+00:00 2026-06-03T13:46:54+00:00

Is it possible to change the class attribute at run-time in C++ language.For example

  • 0

Is it possible to change the class attribute at run-time in C++ language.For example as below :

class base
{
    public:
        //public members

    private : 
        //private members
};

class derived1 : attribute base
{
    public:
        //public members
        base::<base method name> //so that it an be made accessible from the main - outside the class.

    private:
        //private members
};

can the attribute-public,private,protected be changed at runtime, dynamically?

Rgds,
softy

  • 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-03T13:46:55+00:00Added an answer on June 3, 2026 at 1:46 pm

    You cannot change the access modifiers of a class. End of story.

    Disclaimer: There are hacks for just about everything, including this. Don’t use them.

    Based on your comments in the question when asked why you want this, it looks like what you’re trying to do is control access to a class’ run-time properties based on its other run-time properties. For example, maybe a Character‘s Powers are only accessible if Character‘s Level is >= 42.

    This is not a technical question about the mechanics of C++ syntax, but a business logic question. You’ll find the answer to this question in the design of your program and its algorithms — not some technical C++ trick.

    Classes are often used to model things. In your case, a character in a game. Maybe this character has a level and a list of powers (which I’ll represent simply as strings).

    In that case:

    class Character
    {
    public:
      int level_;
      vector<string> powers_;
    };
    

    …is a simplistic representation of your character model. Now, if you want to control access to powers_ at run-time based on the value of level_, you can use an accessor method:

    class Character
    {
    public:
      int level_;
      vector<string> Powers() const 
      {
        if( level_ >= 42 )
          return powers_;
        else
          return vector<string>();
      }
    private:
      vector<string> powers_;
    };
    

    Now you can only get to the character’s powers if the character is of sufficiently high level.

    This is still a highly simplistic example, and the above code is not production quality. However, the idea is there — when implementing your program’s business logic, your focus should be on the algorithms you write much more than the technicalities of C++, or whatever language you’re using.

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

Sidebar

Related Questions

Is it possible to change any properties ( of a class , method or
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is
is it possible to change the value of an attribute of a class using
Is it possible to change PowerPacks.LineShape smoothingMode? I tried to use this code(a class
Is it in any way possible, to change a css class model using JavaScript?
I am starting with this object, public class myTO { private String id; private
All, As the title asks, is it possible to change the __get__ method of
Is it possible to create an attribute for a class that is an array?
Possible Duplicate: jQuery attribute selector for multiple values I have this $('input:radio[name=foo]').change(function() { blah();
I was told the following was possible due to changes in C++11: class SomeType

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.