一直做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;
}
本文介绍了C++中使用__declspec关键字结合属性进行扩展的方法,并通过一个具体的类实例展示了如何定义和使用属性。此外,还列举了多种可用于扩展的属性。
1504

被折叠的 条评论
为什么被折叠?



