Data passing of C++Builder "__property"

704 views Asked by At

Are __properties in C++ Builder passed by reference or by value? ...e.g.

 class TMyClass
 {
 private:
     int FMyFoo1;

     int GetMyFoo2();
     void SetMyFoo2(int AMyFoo2);

 public:
     __property int MyFoo1 = {read=FMyFoo1, write=FMyFoo1};
     __property int MyFoo2 = {read=GetMyFoo2, write=SetMyFoo2};
 };

Also, you can add the & operator to __properties, like

 __property int &MyFoo = {read=FMyFoo};

but only with the Clang based compilers. What's the meaning behind this?

1

There are 1 answers

0
FlKo On

Remy Lebeau has answered my question in a comment:

Declaring a property like

__property DataType PropName = {read=FMember, write=FMember}; 

offers direct access to FMember even though DataType is not declared as a reference. So, if you have a function that takes a DataType& reference as input, and pass PropName to the function, the compiler can still optimize and pass FMember by reference to the function.