这个代码是把Output函数作为一个地址来做的,不知道为什么编译的
时候一直给我报错,可是书上明明可以的啊
错误如下:C:\Users\ADMINI~1\AppData\Local\Temp\ccxuRVz9.o 函数作参数.cpp:(.rdata$.refptr._ZN3ICS6OutputE[.refptr._ZN3ICS6OutputE]+0x0): undefined reference to `ICS::Output'
C:\Users\Administrator\Desktop\collect2.exe [Error] ld returned 1 exit status
#include
using namespace std;
class ICS
{
private:
int a;
int b;
static void (*Output)(int a);
public:
ICS();
void show(void(*thevisit)(int))
{
Output = thevisit;
Output(a);
}
void show1()
{
show(output);
}
};
ICS::ICS()
{
cout << "the sum \n";
cin >> a;
cout << a;
}
void ICS::output(int a)
{
cout << "the number is " << a << endl;
}
int main()
{
ICS I;
I.show1();
return 0;
}