在C++中用C#风格设置类的属性值
来源:互联网 发布:智能锁屏软件 编辑:程序博客网 时间:2024/06/11 20:47
想要实现的效果就是如下这样获取和设置类的属性:
class A{private:int x;};A a;a.x = 1;int b = a.x;
借助VC编译器所支持的属性声明即可实现:
__declspec( property (put=setFunction, get=getFunction) ) data-type property-name;
通过几个宏包装一下:
#define PROPERTY(t,n) __declspec( property ( put = property__set_##n, get = property__get_##n ) ) t n;\typedef t property__tmp_type_##n#define READONLY_PROPERTY(t,n) __declspec( property (get = property__get_##n) ) t n;\typedef t property__tmp_type_##n#define WRITEONLY_PROPERTY(t,n) __declspec( property (put = property__set_##n) ) t n;\typedef t property__tmp_type_##n#define GET(n) property__tmp_type_##n property__get_##n() #define SET(n) void property__set_##n(const property__tmp_type_##n& value)
private: int _x; public: PROPERTY(int, x); GET(x) { return _x; } SET(x) { _x = value; }
细节请见原文:http://www.codeproject.com/Articles/118921/C-Properties
- 在C++中用C#风格设置类的属性值
- Bokeh 风格属性设置
- 在C#中用DirectShow做的媒体播放机
- 在C#中用DirectShow做的媒体播放机
- 在C#中用DirectShow做的媒体播放机
- ApachePOI导出exce,设置单元格风格的属性和设置字体风格的属性的两个工具类,POI宽度和excel 像素转换
- 在C#中用WinAPI
- Android中用代码设置控件属性的注意事项
- C# 属性默认值的设置
- C#中用DataGridView绑定ArcGIS图层的属性表
- C#中用DataGridView绑定ArcGIS图层的属性表
- C#中用关键字来作为属性名的方法
- C#中用关键字来作为属性名的方法
- Ubuntu设置Redhat风格的SHELL提示符PS1属性
- Ubuntu设置Redhat风格的SHELL提示符PS1属性
- Unity3D中用VS2012打开C#代码的设置
- Unity3D中用VS2012打开C#代码的设置
- android中inputType属性在EditText输入值时启动的虚拟键盘的风格
- Jquery让图片根据浏览器窗口大小自动缩放
- android 创建socket 通信型service
- C# dateGRIDVIEW导出EXCEL文件
- JS中截图工具:copper
- Software Craftsmanship : Implement Inversion of Control with Dependency Injection & Service locator
- 在C++中用C#风格设置类的属性值
- No matching function call to 'pthread_create'
- 做一个正气的杭电人
- mysql 远程登录权限设置
- 游戏开发工具之纹理打包器-1.创建界面及连接控件.
- [转]keybd_event 被 SendInput 替代
- Unity 3D 获取手机SD卡目录列表
- How can I always run the command prompt as administrator?
- MC新手入门(四十六)------ 手势支持