#### Archived

This topic is now archived and is closed to further replies.

# Properties and the C++ Standard

This topic is 6425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Once a upon a time I bought my first compiler... and, now, later, I can be glad that that compiler was a Borland Compiler. Because I am what the supermarkets call a ''repeat'' (or otherwise ''loyal'') buyer, I continued buying Borland Compilers. So, buying better and better (and cheaper and cheaper until one day... wonderiously... it was FREE) I finally bought C++Builder 5. First reaction: Oh My god. Well ok not that good but the main thing that caught my eye at the time was properties (and of course the fact that normal Win32 apps were made so ridicously easy a 10 year old could do it... I ain''t joking. But it is still as fast as normal C++!) like: class XYZ { private: int fx; public: __property int x = {read=Fx,write=Fx}; }; Ok the main thing is, do you (as MS VC honed programmers) feel that the __property is a GOOD thing? Is it worth adding to the C++ language? The above example wasn''t so good, the main thing I like about them is that it allows side-effects on accessing or setting a property: class XYZBetter { private: MyColor FColor; void SetColor(MyColor New); //will actually set the color on screen or wherever, not just the FColor.. public: __property int Color = {read=FColor,write=SetColor}; }; The main thing about properties is it''s simplicty. Ex: What would you rather do: int x = Test.GetX(); int y = GetNewXFromUser(x); Test.SetX(y); or: int x = Test.x; int y = GetNewXFromUser(x); Test.x = y; Hopefully some C++Builder programmers can come forward and support me against the hordes of VC people (only joking I don''t _hate_ MS products, there just not that good

##### Share on other sites
Haven''t ever heard of this before, but from your example, a property will act like a member variable that can do different things depending on whether you are reading or writing? Is this correct.

If so, it''s definitely another tool that might be appropriate in places, but it seems that it''d lead to code obfuscation.

##### Share on other sites
Having used C++Builder and MSVC, here''s what I think: C++Builder is a VERY good development system. I loved it, when I used to use it. I do use VC++ more though, simply because everybody uses it. I think the __property is a good addition to the C++Builder compiler, because it''s for use with the RAD system, but I think to include it in the language would sort of be a little bit too related to the development environment you''re using. (did that make sense?).

##### Share on other sites
isnt that basicly the same as making a function like
public:
int GetX(){return x};
void SetX(int X)(x=X);

its not like it takes to much extra effort

Im Always Bored
--Bordem
ICQ: 76947930

##### Share on other sites
True, I can see now that I _have_ gotten used to the system in C++Builder. About the Getter/setters, __propertys go past that, like:
__property MyStream* Streams[char* FileName] = {read=GetStreams};
This could be used for a pak file for example. Again the point is that it''s just simpler. Also if you have direct access to a variable, like the example up top, the compiler will replace the property with the real value (no performance ''hit'' I guess) but with the proper OOP way of doing things like you can have read-only properties which cannot be changed. You even can have multidimenional properties. Granted, they are like getter/setters, but simpler to use. Which makes them better. Right?

##### Share on other sites
BTW, under VC++ it works like this:
__declspec( property( get=get_func_name ) ) declarator

__declspec( property( put=put_func_name ) ) declarator

__declspec( property( get=get_func_name, put=put_func_name ) ) declarator

It is also about to use [] for the first few parameters if they're integer types:
__declspec(property(get=GetX, put=PutX)) int x[];The above statement indicates that x[] can be used with one or more array indices. In this case, i=p->x[j][k] will be turned into i=p->GetX(j, k), and p->x[j][k] = i will be turned into p->PutX(j, k, i);

Edited by - Freeside on July 20, 2000 10:41:08 AM

Edited by - Freeside on July 20, 2000 10:42:27 AM

##### Share on other sites
Cool! I never knew VC could do that! Ok, then, all I have to do is change all my properties into a macro that expands differently if you got VC or BCB....