function pointer x + y

#include <iostream>
using namespace std;

double add (double x, double y)
{
    return x + y;
}

double calculate (double m, double n, double (*pf)(double, double))
{
    return (*pf)(m, n);
}

int main()
{
    double sum = 0;
    double a, b;
    cin >> a >> b;
    sum = calculate(a,b,add);
    cout << sum << endl;
    return 0;
}

  1、函数的parameter和返回类型必须与相对应的函数指针类型一致。

  2、如果(*pf)是函数,那么pf就是该函数的指针。

注意 double (*pf) (int);  是指 pf指向一个返回double类型的函数。

  double *pf(int); 指 pf()函数返回一个double类型的指针。

时间: 2024-07-31 02:11:26

function pointer x + y的相关文章

C++, function pointer

0. Function pointers are among the most powerful tools in C.  It can be used to implement function callback in C. C++ takes a slightly different route for callbacks. 1. Function pointer // (1)define a function bool lengthCompare(const string&, const

类非静态成员的函数指针 的使用 Function pointer of a non-static member function of a class

you can get the pointer of the method, but it has to be called with an object typedef void (T::*MethodPtr) (); MethodPtr method = &T::MethodA; T *obj = new T(); obj->*method(); If you need to have non-object pointer and you want to use object then

tips~function pointer

An simple example: #include<stdio.h> int plus(int a,int b) { return a+b; } int main() { int (*func)(int,int); func=&plus; //point to the function ''plus(int,int)'' printf("the result is %d\n",(*func)(4,7)); return 0; } Another example:

jquery 拖拽变换位置

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>测试</title><style>.item_content ul { list-style: none; }.item_content ul li { width: 200px; height: 160px; float: left; margin: 10px }.item_content

从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中

1,实现功能:从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中 并实现app向后移动一个元素的位置: 2.实现思路: 01.遍历下拉菜单,添加拖拽方法,实现位置移动功能: 02.遍历app列表,将app位置存为数组,进行循环: 03.拖拽元素与当前app做碰撞检测: 04.如果鼠标在app内部,则将拖拽元素添加到当前app之后,位置设置为当前 i 的值: 参考代码如下: <!doctype html> <html lang="en"> <head

Jquery 多行拖拽图片排序 jq优化

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery图片拖动排序代码</title> <style type="text/css"> .item_container{position:relative;height:auto;overflow:hidden;} .item_content ul{list-

Callback Function

typedef void (*callbackFun)(int a, int b);struct exm { int type; callbackFun fun;}; A pointer is a special kind of variable that holds the address of another variable. The same concept applies to function pointers, except that instead of pointing to

implicitly declaring library function &#39;objc_msgSend&#39;with type &#39;(id,SEL,...)&#39; 警告

之前一直用objc_msgSend,但是没注意apple的文档提示,所以突然objc_msgSend crash了. 之前32位的时候没问题,然后转换为64位之后就会发生EXC_BAD_ACCESS问题. 当然apple再文档([64-Bit Transition Guide for Cocoa Touch中有](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/CocoaTou

std::map, struct pointer 为key

template < class Key, // map::key_type class T, // map::mapped_type class Compare = less<Key>, // map::key_compare class Alloc = allocator<pair<const Key,T> > // map::allocator_type > class map; struct Cell{ int x; int y; Cell(int