回调函数 typedef bool (*IsUsed)(const string &name,boost::shared_ptr<ShpGeometry> oneGeometry);
就是指向函数的指针。
回调函数,表示了一个函数的地址,将函数作为参数进行使用。参考百度百科:http://baike.baidu.com/view/414773.htm
常用的大概就是在sort函数中了吧。
回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数。回调函数不是由该函数的实现方直接调用,而是在特定的事件或条件发生时由另外的一方调用的,用于对该事件或条件进行响应。
例子如下:
函数:typedef int (__stdcall *CompareFunction)(constbyte*,constbyte*)
使用者:void DLLDIR __stdcall Bubblesort(byte* array,int size,int elem_size,CompareFunction cmpFunc);使用者:void DLLDIR __stdcall Quicksort(byte* array,int size,int elem_size,CompareFunction cmpFunc);void DLLDIR __stdcall Bubblesort(byte* array,int size,int elem_size,CompareFunction cmpFunc)
{
for(int i=; i < size; i++)
{
for(int j=; j < size-i-; j++)
{
//回调比较函数
if( == (*cmpFunc)(array+j*elem_size,array+(j+)*elem_size))
{
//两个相比较的元素相交换
byte* temp = new byte[elem_size];
memcpy(temp,array+j*elem_size,elem_size);
memcpy(array+j*elem_size,array+(j+)*elem_size,elem_size);
memcpy(array+(j+)*elem_size,temp,elem_size);
delete [] temp;
}
}
}
}
int __stdcall CompareInts(const byte* velem1,const byte* velem2)
{
int elem1 = *(int*)velem1;
int elem2 = *(int*)velem2;
if( elem1 < elem2 )
return -;
if(elem1 > elem2)
return ;
return ;
}
int __stdcall CompareStrings( const byte* velem1, const byte* velem2 )
{
const char* elem1 = (char*)velem1;
const char* elem2 = (char*)velem2;
return strcmp(elem1,elem2);
}
应用:
Bubblesort((byte*)array,5,sizeof(array[0]),&CompareInts);
Quicksort((byte*)str,5,10,&CompareStrings);
回调函数 typedef bool (*IsUsed)(const string &name,boost::shared_ptr<ShpGeometry> oneGeometry);的更多相关文章
- typedef void(*Fun) (void)是什么意思 函数指针(回调函数) 和函数对象总结
https://blog.csdn.net/FreeApe/article/details/49124043 bool (*pf)(const string &,const string &a ...
- 编写函数,接受一个string,返回一个bool值,指出string是否有5个或者更多字符,使用此函数打印出长度大于等于5的元素
#include <algorithm> using namespace std; bool isFive(const string& s1) { return s1.size() ...
- Zookeeper C API 指南三(回调函数)(转)
2013-02-21 12:54 by Haippy, 9237 阅读, 0 评论, 收藏, 编辑 接上一篇<Zookeeper C API 指南二(监视(Wathes), 基本常量和结构体介绍 ...
- cocos2dx[3.2](10) 新回调函数std::bind
在2.x中处理事件需要用到委托代理(delegate),相信学过2.x的触摸事件的同学,都知道创建和移除的流程十分繁琐. 而在3.x中由于加入了C++11的特性,而对事件的分发机制通过事件分发器Eve ...
- VC++ 回调函数及使用方法(转)
转载:http://blog.csdn.net/vsooda/article/details/7435801 转载:http://blog.csdn.net/lincyang/article/deta ...
- SetTimer 与 回调函数
在控制台应用程序中,SetTimer的函数原型为: UINT_PTR SetTimer( HWND hWnd, // handle to window UINT_PTR nIDEvent, // ti ...
- 转:Delphi 回调函数及例子
http://anony3721.blog.163.com/blog/static/5119742010866050589/ { http://anony3721.blog.163.com/blog/ ...
- android 回调函数的使用
// activity 之间方法调用的桥梁 public class ActivityCallBridge { static ActivityCallBridge mBridge; private O ...
- Delphi回调函数及其使用
Delphi回调函数及其使用 1 回调函数的概述 回调函数是这样一种机制:调用者在初始化一个对象(这里的对象是泛指,包括OOP中的对象.全局函数等)时,将一些参数传递给对象,同时将一个调用者可以访问的 ...
随机推荐
- 私有DockerHub搭建
docker简介 一个开源的应用容器引擎,可以用来打包程序,可以包入依赖环境,这样只需要提供docker image即可,类似于虚拟机,但是更轻量级. 几个概念: Paas,platform as a ...
- leetcode-25-exercise_string&array
14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...
- poj-1700 crossing river(贪心题)
题目描述: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...
- HDU4010 Query on The Trees (LCT动态树)
Query on The Trees Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Othe ...
- loj2021 「HNOI2017」大佬
there #include <algorithm> #include <iostream> #include <cstring> #include <cst ...
- webdriver高级应用- 浏览器中新开标签页(Tab)
#encoding=utf-8 import unittest from selenium import webdriver import time import win32api, win32con ...
- Selenium WebDriver-actionchain模拟鼠标右键操作
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- ora flashback详解
使用oracle数据库时,难免会碰到一些问题. 例:1.如何回滚已经commit了的数据 2.如何查询已经被覆盖掉的数据[update],或者被delete了的数据 3.如何将数据恢复到某个时间点 我 ...
- python中用exit退出程序
在python中运行一段代码,如果在某处已经完成整次任务,可以用exit退出整个运行.并且还可以在exit()的括号里加入自己退出程序打印说明.不过注意在py3中要加单引号或双引号哦!
- [git 学习篇] 关联github和本地创库
所以,github和本地创库是通过ssh传送,所以要将公钥拷贝到远程创库上(比如我ssh 远程服务器时,先将本地的公钥,拷贝到远程服务器的某个文件上(http://www.cnblogs.com/li ...