properties in c++

Posted on 2011-05-12
Medium Priority
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:Mydeen Yussouf
  • 2
LVL 40

Accepted Solution

evilrix earned 500 total points
ID: 35750697
>> 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 40

Expert Comment

ID: 35750705
>> some compilers support them as an extension

For example: http://msdn.microsoft.com/en-us/library/yhfk0thd(v=VS.80).aspx

Assisted Solution

pcunite earned 500 total points
ID: 35757525
They are not part of the standard, but there are libraries out there that use templates to accomplish this:

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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