[C++] 纯文本查看 复制代码
#include "stdafx.h"
#include <iostream>
using namespace std;
//输出 count 个空格
void space(int count)
{
for (; count; count--) cout << ' ';
}
//输出 count 个字符 ch
void space(int count, char ch)
{
for (; count; count--) cout << ch;
}
int _tmain(int argc, _TCHAR* argv[])
{
//创建一个指向带有一个整型参数函数的函数指针
void (*fp1)(int);
//创建一个指向带有一个整型参数和一个字符参数的函数的函数指针
void (*fp2)(int, char);
fp1 = space; //获得函数 space(int) 的地址
fp2 = space; //获得函数 space(int, char) 的地址
fp1(22); //输出 22 个空格, 也可以 (*fp1)(22) 这么使用
cout << "|\n";
fp2(30, 'x'); //输出 30 个x, 也可以 (*fp2)(30, 'x') 这么使用
cout << "|\n";
return 0;
}