Borland C + + Builder extensions to C + + and can also customize class attributes like Delphi. For properties of a simple type, you can define the following:
class TSome
{
protected:
int a;
int b;
int s;
int GetSum(void){ return s = a + b ; }
void SetSum(int s){ this->s = s ; }
public:
//...其它代码
__property int sum={read=GetSum,write=SetSum};
//...
};//end class
--------------------------------------------------------------------------------
For properties of an array type, you can define the following:
class TSome
{
private:
TList *list;
protected:
void* GetItem(int i){ return (i >= 0 && i < list->Count ) ? list->Items[i] : NULL ; }
void SetItem(int i,void*ptr){ list->Insert(i,ptr); }
int GetCount(void){return list->Count;}
public:
TSome(void){ list = new TList( ); }
~TSome(void){ if( list ) delete list; }
//...其它代码
__property void* item[int i]={read=GetItem,write=SetItem};
__property int count={read=GetCount};
//...
};//end class
Note: "Properties" are intuitive and concise to use, but as a commercialized software, you should not forget to catch any exceptions that might be thrown [exceptions] while using attributes.