[百度空间] [note] pointer to member is a POD type
2015-05-18 18:43
295 查看
C++033.9-10:
Asweallknowsthepointertomembermaynotbecastintovoid*(GCCisOKbutit'saspecialcaseanyway),accordingtothestandradwecanstorethepointertomembertoacharbufferthough.Unfortunately,thesizeof"pointertomember"isimplementationdefined,sowestillneedsomehackfordifferentcompilers.
here'satableforsizeof(pointertomember)forsomecompilers
(http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible)
theoriginalarticleimplementeachcompiler'spointertomembermechanism,whichIbelieveisinsane,it'sdefinitelynotagoodwaytowriteportablecodes.here'swhatI'mdoing(codesnippet).
所以pointertomember可以被保存在bytearray里面再被解出来.这对于做delegate很有帮助.这是我目前使用的方法.
there'saveryefficientwaytodothedelegate:
http://www.codeproject.com/Articles/11015/The-Impossibly-Fast-C-Delegates
他也是用模板函数,但不同的是把函数地址作为模板参数.本来打算改用这个方法的.但是唯一的缺点就是需要显式指定模板参数<>来实例化,而构造函数只能通过TAD来套用模板参数,不能显式指定...所以他用的是一个静态模板函数来构造一个对象
而我使用的方式虽然多了一个char[],有一点点额外的内存开销和运行时开销,但是大多数情况下几乎可以忽略不计.
主要是可以通过TemplateArugmentDeduction直接创建delegate,比如:
所以考虑了一下,决定暂时不用他的那种方法(用起来稍微不方便,但是效率非常高).以后看情况再考虑要不要改.
另外,作为一个C++程序猿,个人觉得"数据绑定","反射","代理",这些使用时尽量谨慎,不可滥用.除了在event/msg和UI/Tools的极少数地方要用以外,其他地方还是尽量不要用为好.最近把数据绑定框架做了简单重构,幸好用到的地方不多(主要是编辑器在用),要不然重构就哭了.目前还没有反射,暂时不需要,以后需要时再加.最好是另外封装,不影响现在的代码.
Arithmetictypes( 3.9 . 1 ),enumerationtypes,pointertypes,andpointertomembertypes( 3.9 . 2 ),andcv-qualifiedversionsofthesetypes( 3.9 . 3 )arecollectivelycalledscalartypes.Scalartypes,POD-structtypes,POD-uniontypes(clause 9 ),arraysofsuchtypesandcv-qualifiedversionsofthesetypes( 3.9 . 3 )arecollectivelycalledPODtypes. |
here'satableforsizeof(pointertomember)forsomecompilers
(
所以pointertomember可以被保存在bytearray里面再被解出来.这对于做delegate很有帮助.这是我目前使用的方法.
他也是用模板函数,但不同的是把函数地址作为模板参数.本来打算改用这个方法的.但是唯一的缺点就是需要显式指定模板参数<>来实例化,而构造函数只能通过TAD来套用模板参数,不能显式指定...所以他用的是一个静态模板函数来构造一个对象
主要是可以通过TemplateArugmentDeduction直接创建delegate,比如:
另外,作为一个C++程序猿,个人觉得"数据绑定","反射","代理",这些使用时尽量谨慎,不可滥用.除了在event/msg和UI/Tools的极少数地方要用以外,其他地方还是尽量不要用为好.最近把数据绑定框架做了简单重构,幸好用到的地方不多(主要是编辑器在用),要不然重构就哭了.目前还没有反射,暂时不需要,以后需要时再加.最好是另外封装,不影响现在的代码.
相关文章推荐
- Is the type of “pointer-to-member-function” different from “pointer-to-function”?
- Pointer to incomplete class type is not allowed
- pointer to incomplete class type is not allowed是什么错误?
- pointer to incomplete class type is not allowed 错误
- 前向声明之“Error: pointer to incomplete class type is not allowed.”
- [Builderror]pointer to incomplete class type is not allowed
- C++11 type_traits 之is_pointer,is_member_function_pointer源码分析
- 【C++】如何解决“pointer to incomplete class type is not allowed”。
- Error[Pe393]: pointer to incomplete class type is not allowed
- 转:[Java] Access restriction: The type FtpClient is not accessible due torestriction on required libr
- Access restriction: The type Resource is not accessible due to restriction on required library
- Access restriction: The type * is not accessible due to restrict,报错问题
- Access restriction: The type JFrame is not accessible due to restriction on required library
- Access restriction: The method XXX from the type XXX is not accessible due to restriction XXX
- gcc编译出现:error: dereferencing pointer to incomplete type
- shared_ptr.hpp(321) : error C2039: 'type_info' : is not a member of 'std' 错误修正
- 条款24:若所有参数皆需要类型转换,请为此采用non-member函数(Declare non-member functions when type conversions should apply to all parameters)
- 解决办法:Access restriction: The type JPEGImageEncoder is not accessible due to restriction
- Access restriction: The type * is not accessible due to restrict,报错问题,只试过第二种,OK。
- Unable to add module to the current project as it is not of packaging type 'pom'