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;
 - }
 
C++属性相关概念就为大家介绍到这里。
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号