c++属性

来源:互联网 发布:清华教授 软件学院 编辑:程序博客网 时间:2024/05/22 21:19

一直做c#不过对c++也比较感兴趣 可是c++不支持属性扩展下吧

解释下

__declspec”是Microsoft c++中专用的关键字,它配合着一些属性可以对标准C++进行扩充。这些属性有:
align、allocate、deprecated、dllexport、dllimport、 naked、noinline、noreturn、nothrow、novtable、selectany、thread、property和uuid。

template <class T1, class T2> class KeyValuePair
{
    
private:

 
//-- 参数
 T1  *Key;

 
//------值
 T2 *Value;
 
public
     :
 KeyValuePair()
 {
    Key
=new T1;
    Value
=new T2;
 }
 
~KeyValuePair()
 {
    delete Key;
    delete Value;
 }

public :
        T1 GetKey()
 {
    
return this->Key;
 }
 T1 SetKey(T1 inputKey)
 {
    
this->Key=inputKey;
 }

private :
    
int m_old;

public:
    
//---------属性----get--------set--------返回数据---属性名称
    _declspec(property(get=GetOld,put=SetOld))int Old; 

  
int GetOld(void)
   {
    
return m_old;
   }

   
void SetOld(int value)
   {
   
      m_old
=value;
   }
};

int main(int argc, char* argv[])
{
KeyValuePair
<int,int> c1;

c1.Old
=123;
cout
<<c1.Old;
}