找回密码
 立即注册
查看: 361|回复: 11

话说我的吸++版属性撸出来了

[复制链接]

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

发表于 2014-4-19 20:42:19 | 显示全部楼层 |阅读模式
  1. template <typename T>
  2. class _property{
  3. public:
  4.         using Get = std::function<T()>;
  5.         using Set = std::function<void(const T&)>;
  6.         _property(Get fng, Set fns){ _get = fng; _set = fns; }
  7.         const T& operator=(const T& value){ _set(value); return value; }
  8.         operator T(){ return _get(); }
  9. private:Get _get; Set _set;
  10. };
  11. #define PROPERTY(Type,get,set,name)\
  12. _property<Type> name = { _property<Type>::Get([&]()##get), _property<Type>::Set([&](const Type& value)##set) }
  13. class sample{
  14. public:
  15.         PROPERTY(int,
  16.         {
  17.                 std::cout << "property get" << std::endl;
  18.                 return ival;
  19.         },
  20.         {
  21.                 ival = value;
  22.                 std::cout << "property set" << std::endl;
  23.         },
  24.                 INTVAL);
  25. private:
  26.         int ival;
  27. };
  28. int main()
  29. {
  30.         sample sp;
  31.         sp.INTVAL = 1;
  32.         std::cout << (sp.INTVAL + 5) << std::endl;
  33.         std::cin.get();
  34. }
复制代码


While the truncheon may be used in lieu of conversation words will always retain their power.
回复

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-4-19 20:44:58 | 显示全部楼层
感谢党和国家 感谢吸加加11 感谢lambda 感谢std::function
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

1万

回帖

1万

基友

2万

积分

末日审判

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

发表于 2014-4-19 20:45:01 | 显示全部楼层
sf妥妥的

评分

参与人数 1基友 +100 收起 理由
Rise + 100 沙发

查看全部评分

回复

使用道具 举报

51

回帖

39

基友

115

积分

凡人2阶 Lv.2

Rank: 1

伯爵荣耀

发表于 2014-4-19 21:52:36 | 显示全部楼层
目标四级继续努力
回复 支持 反对

使用道具 举报

1249

回帖

2万

基友

2万

积分

萨菲尔斯

【直♂男】

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

苍海的女仆伯爵荣耀

发表于 2014-4-19 22:11:42 | 显示全部楼层
神马破玩意,又是抄袭我大CF的吧
Five贴吧个人网站www.fivekuai.com
回复 支持 反对

使用道具 举报

2034

回帖

2万

基友

2万

积分

仙人7层 Lv.16

Invincible

Rank: 10Rank: 10Rank: 10

 楼主| 发表于 2014-4-19 22:13:04 | 显示全部楼层
5块用一个月 发表于 2014-4-19 22:11
神马破玩意,又是抄袭我大CF的吧

明明是抄袭cs→_→
While the truncheon may be used in lieu of conversation words will always retain their power.
回复 支持 反对

使用道具 举报

7563

回帖

1万

基友

2万

积分

仙人7层 Lv.16

Rank: 10Rank: 10Rank: 10

发表于 2014-4-20 06:18:46 | 显示全部楼层
不明觉牛
回复

使用道具 举报

7563

回帖

1万

基友

2万

积分

仙人7层 Lv.16

Rank: 10Rank: 10Rank: 10

发表于 2014-4-20 06:18:55 | 显示全部楼层
帮顶
回复

使用道具 举报

1220

回帖

5118

基友

4428

积分

通神6段 Lv.9

Rank: 5Rank: 5

发表于 2014-4-20 08:45:34 | 显示全部楼层
代源码?→_→
回复 支持 反对

使用道具 举报

8614

回帖

3万

基友

2万

积分

仙人8层 Lv.17

Rank: 11Rank: 11Rank: 11Rank: 11

伯爵荣耀

发表于 2014-4-20 10:55:17 | 显示全部楼层
路过。。。
回复

使用道具 举报

1万

回帖

1万

基友

2万

积分

末日审判

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

发表于 2014-4-20 13:52:33 | 显示全部楼层
妈蛋,我昨天明明是抢到沙发了
回复 支持 反对

使用道具 举报

154

回帖

235

基友

638

积分

通神1段 Lv.4

Rank: 2

伯爵荣耀

发表于 2014-4-20 16:09:39 | 显示全部楼层
围观
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|苍海国际 ( 鲁ICP备13020644号-1 )

GMT+8, 2025-7-10 03:08 , Processed in 0.060308 second(s), 31 queries .

Powered by Discuz! Theme By eRic Modified by 4bpa

© CangHai International We Do Our Rights!

返回顶部