?
Solved

properties in c++

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

Ex:

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++?
0
Comment
Question by:Mydeen Yussouf
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
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"
http://e-e.com/A_3843.html
0
 
LVL 40

Expert Comment

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

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

Assisted Solution

by:pcunite
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:
http://www.codeproject.com/KB/cpp/genericproperty.aspx
0

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