stack类中定义StackTraverse, Visit函数如下:
Status stack::StackTraverse(SqStack S, Status(* visit)(SElemType)) //访问栈元素
{
while (S.pTop > S.pBase)
{
Visit(*(S.pBase++));
}
printf("\n");
return OK;
}
Status stack::Visit(SElemType e) //浏览栈元素
{
printf("%d\t", e);
return OK;
}
附:
typedef int SElemType;
typedef int Status;
进行调用时:
printf("栈中的元素依次为:");
g_MyStack.StackTraverse(g_MyStack.m_SqStack, g_MyStack.Visit);
发生错误如下:
E:\NewCal\NewCal.cpp(36) : error C2664: 'StackTraverse' : cannot convert parameter 2 from 'int (int)' to 'int (__cdecl *)(int)'
None of the functions with this name in scope match the target type
请问第二个参数的传递类型为什么不对,应该怎么改正,十分感谢!
两个函数的定义不同,强制转换下
g_MyStack.StackTraverse(g_MyStack.m_SqStack, (int (__cdecl *)(int))g_MyStack.Visit);