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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:06:11+00:00 2026-05-27T13:06:11+00:00

I’m coming from a background in languages like Actionscript 3 where we have a

  • 0

I’m coming from a background in languages like Actionscript 3 where we have a special way of defining a member variable as both an instance and a method for setting/fetching the value of a protected or private member. Let me give an example:

Within a class, we can say something like this:

private var _myString:String;

public get myString():String 
{
    return _myString;
}

public set myString(newValue:String):void
{
    //Do some super secret member protection n' stuff
    _myString = newValue;
}

And then outside of that object I can do the following:

trace(myClass.myString); //Output whatever _myString is. (note the lack of (). It's being accessed like property not a method...

And even further, I could do something like delete the “public set myString” method, so if someone tried to do this with my class:

myClass.myString = "Something"; //Try to assign - again note the lack of ()

It would throw an error, letting the user know that the property is available as read-only.

Now since I’m using C++ and it’s infinitely more awesome than Actionscript 3, I’m wondering how I can mimic this type of behavior. I don’t want to use a bunch of dirty getVariable() and setVariable() methods. I was hoping through some operator overloading trickery I could make the exact same thing possible here. Note I am a noob, so please address me as such. 🙂

Update
I guess the easiest way to explain this is, I’m trying to essentially have getters and setters but invoke them through assignment rather than with the parentheses ().

  • 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-27T13:06:12+00:00Added an answer on May 27, 2026 at 1:06 pm

    Sorry, with C++, the syntactic sugar is not there, which means you have to implement the get/set methods yourself.
    So in your case you will have to implement a getVariable() method without it’s equivalent Set method in order to make it read only.

    And please don’t resort to macro’s to make it Look like you have some read only properties. That will just piss people off when they read your code 5 years from now.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't

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.