properties in c++

Posted on 2011-05-12
Last Modified: 2012-05-11
In some libraries I see functions that work as both get/set accessors.


string str = pField->AsString
pField->AsString = GetDestHost().c_str();

The function documentation is as below(C++ Builder):

__property System::UnicodeString AsString = {read=GetAsString, write=SetAsString};

How does it work? As it is related, How are properties implemented in C++?
Question by:olmuser
    LVL 39

    Accepted Solution

    >> How are properties implemented in C++?
    They ain't; at least not natively as part of the C++ standard but some compilers support them as an extension.

    You might find my article interesting.
    "How to add properties to standard C++ classes"
    LVL 39

    Expert Comment

    >> some compilers support them as an extension

    For example:
    LVL 6

    Assisted Solution

    They are not part of the standard, but there are libraries out there that use templates to accomplish this:

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now