C++编程语言中的属性是一个比较基础的知识概念,我们初学者们在学习的过程中需要对这一基础知识有一个深刻的认识,以方便将来的应用。在这里就一起来了解一下C++属性的相关概念。
“__declspec”是Microsoft c++中专用的关键字,它配合着一些属性可以对标准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--------返回数据---C++属性名称
_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;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
C++属性相关概念就为大家介绍到这里。
【编辑推荐】