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

  • SEARCH
  • Home
  • 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 1086643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:50:20+00:00 2026-05-16T22:50:20+00:00

How to Define or Implement C# Property in ISO C++ ? Assume following C#

  • 0

How to Define or Implement C# Property in ISO C++ ?

Assume following C# code :

int _id;

int ID
{
    get { return _id; }
    set { _id = value; }
}

I know C# convert the get and set lines to getXXX and setXXX methods in compile time. in C++ , programmers usually define these two function manually like :

int _id;

int getID() { return _id; }
void setID(int newID) { _id = newID; }

but, I want to have the C# syntax or a stuff like it in order to have a simple usability.
In C#, we can use properties like :

ID = 10;              // calling set function
int CurrentID = ID;   // calling get function

In C++, we can use our function like :

setID(10);                 // calling set function
int CurrentID = getID();   // calling get function

Now tell me how can I implement the C# properties in ISO C++.

thanks.

  • 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-16T22:50:20+00:00Added an answer on May 16, 2026 at 10:50 pm

    As Alexandre C. has already stated, it’s very awkward and not really worth it, but to give an example of how you might do it.

    template <typename TClass, typename TProperty>
    class Property
    {
        private:
            void (TClass::*m_fp_set)(TProperty value);
            TProperty (TClass::*m_fp_get)();
            TClass * m_class;
    
            inline TProperty Get(void)
            {
                return (m_class->*m_fp_get)();
            }
    
            inline void Set(TProperty value)
            {
                (m_class->*m_fp_set)(value);
            }
    
        public:
            Property()
            {
                m_class = NULL;
                m_fp_set = NULL;
                m_fp_set = NULL;
            }
    
            void Init(TClass* p_class, TProperty (TClass::*p_fp_get)(void), void (TClass::*p_fp_set)(TProperty))
            {
                m_class = p_class;
                m_fp_set = p_fp_set;
                m_fp_get = p_fp_get;
            }
    
            inline operator TProperty(void)
            {
                return this->Get();
            }
    
            inline TProperty operator=(TProperty value)
            {
                this->Set(value);
            }
    };
    

    In your class where you wish to use it, you create a new field for the property, and you must call Init to pass your get/set methods to the property. (pref in .ctor).

    class MyClass {
    private:
        int _id;
    
        int getID() { return _id; }
        void setID(int newID) { _id = newID; }
    public:
        Property<MyClass, int> Id;
    
        MyClass() {
            Id.Init(this, &MyClass::getID, &MyClass::setID);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Define the following C# interface: public interface IShape { int NumberOfLineSegments {get;} int Area
I try to implement User define Delegate.For that i did this code **- DelegateAppDelegate.h**
Is it possible to define an interface (e.g. MyClass Implements MyInterface) whose method/property definitions
Basically I want to implement a simple Rails extension to define the seriousness of
I have the following sample code in a VB.NET console application. It compiles and
I'm trying to implement generic method to put in a class a calculated value
Dear Spring community, What I am trying to implement is the following: I would
Consider the class: public class foo { public object newObject { get { return
Is there a way to implement auto-complete functionality in a region defined by textarea
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like

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.