主题:请教牛人一个问题
grace_lilian
[专家分:0] 发布于 2011-11-01 18:58:00
请教牛人一个问题
定义的类里的两个函数,函数1被函数2调用,函数1具有返回值。
在运行时,当运行到函数2中的函数1时,函数1可运行,但是在函数2中生成不了返回值
如何测试问题??
回复列表 (共16个回复)
沙发
windy0will [专家分:2300] 发布于 2011-11-01 19:00:00
用printf函数输出必要的信息,这种问题应该很好解决的。
板凳
grace_lilian [专家分:0] 发布于 2011-11-01 19:04:00
函数1的内容都可以正常输出,但是想用函数2输出函数1的返回值,程序就停在那里了。
3 楼
windy0will [专家分:2300] 发布于 2011-11-01 19:07:00
把你的代码发出来吧,这样凭空说可能也讨论不出什么结果。
4 楼
grace_lilian [专家分:0] 发布于 2011-11-01 19:07:00
[quote]用printf函数输出必要的信息,这种问题应该很好解决的。[/quote]
而且,程序正常运行,还没有报任何的错,只是运行到这一步就停住了。不运行函数2的打印函数1的返回值,只执行了函数2调用的函数1.
5 楼
grace_lilian [专家分:0] 发布于 2011-11-01 19:10:00
pathFinder 函数调用getMinFOfSubNode函数
getMinFOfSubNode函数应该返回一个bool型值
bool graphType< Type, size >:: getMinFOfSubNode( const nodeType<Type>* currentNode, nodeType<Type>* minNode )
{
int i;
nodeType<Type>* current;
linkedQueueType<Type> subNodeList; //把子节点放入一个链表
//openList.printQueue(); //测试
printSubNodes( currentNode );
for( i = 0; i < 8; i++ ) //计算子节点的Fcost,并把子节点加入一个表
{
current = currentNode->connectedNodes[i];
if( current != NULL )
{
cout << endl;
/*
//测试
cout << "IN GETMINFOFSUBNODE: currently connected nodes is graph[" << current->x << "][" << current->y << "] " << endl;
openList.printQueue();
if( !openList.searchQueue( *current ) )
cout << "IN GETMINFOFSUBNODE:: no such node in open." << endl;
if( !closedList.searchQueue( *current ) )
cout << "IN GETMINFOFSUBNODE:: no such node in closed." << endl;
*/
resetFCost( current, currentNode );
//测试
//cout << "IN getMinFOfSubNode: subNodeList.addQueue " << endl;
subNodeList.addQueue( current ); //加入子节点队列
}
}
//查找最小fcost的子节点
/*
//测试
cout << "IN SUBNODELIST: " << endl;
subNodeList.printQueue();
cout << endl;
//测试结束
*/
current = subNodeList.getFront();
//测试
//cout << "IN getMinFOfSubNode: first current sub node: graph[" << current->x << "][" << current->y << "]" << endl;
minNode = current;
while( current != NULL )
{
/*
//测试
cout << " minNode->fCost: " << minNode->fCost << endl;
cout << " currentNode->fCost: " << current->fCost << endl;
//测试结束
*/
if( minNode->fCost > current->fCost ) //如果minSubNode所指向的子节点的fCost大于当前子节点的fCost,则指向当前子节点
minNode = current;
/*
//测试
cout << " testNode->fCost: " << minNode->fCost << endl;
cout << " currentNode->fCost: " << current->fCost << endl;
//测试结束
*/
current = current->next;
}
//测试
cout << "IN getMinFOfSubNode: the min fcost sub node is: graph[" << minNode->x << "][" << minNode->y << "] " << endl;
cout << "IN getMinFOfSubNode: It's fcost is: " << minNode->fCost << endl;
if( minNode == NULL )
return 0;
else
{
cout << "minNode find sucessfull! Return to pathFinder..." << endl;
return 1;
}
//测试结束
}
6 楼
grace_lilian [专家分:0] 发布于 2011-11-01 19:10:00
template< class Type, int size >
void graphType< Type, size >::pathFinder()
{
nodeType<Type> *currentNode; //指向当前节点
nodeType<Type>* minNode; //指向当前节点的某个子节点
minNode = NULL;
currentNode = startNode;
//openList.printQueue(); //测试
while( currentNode != finishNode )
{
openList.addQueue( currentNode ); //把当前节点加入open表
//测试
if( currentNode == &graph[0][0] )
cout << "IN pathFinder: Get min fcost of graph[" << currentNode->x << "][" << currentNode->y << "]'s sub nodes: " << endl;
//测试结束
//测试
if( minNode == NULL )
cout << "IN pathFinder: minNode == NULL" << endl;
else
{
cout << "Found minNode." << endl;
cout << "IN pathFinder: the min fcost sub node is: graph[" << minNode->x << "][" << minNode->y << "] " << endl;
}
//测试结束
[color=FF0000] /////////////////错误,程序运行到此处无法打印返回值,但是却执行了函数[/color]getMinFOfSubNode
cout << getMinFOfSubNode( currentNode, minNode ) << endl; //找到该节点的最小fcost节点
//测试
if( minNode == NULL )
cout << "minNode == NULL." << endl;
else
{
cout << "Found minNode." << endl;
cout << "IN pathFinder: the min fcost sub node is: graph[" << minNode->x << "][" << minNode->y << "] " << endl;
}
//测试结束
下面的省略
7 楼
windy0will [专家分:2300] 发布于 2011-11-01 19:11:00
是不是用了scanf等函数,然后是按 Ctrl+Z 或 Ctrl+C结束程序。
8 楼
grace_lilian [专家分:0] 发布于 2011-11-01 19:13:00
[quote]是不是用了scanf等函数,然后是按 Ctrl+Z 或 Ctrl+C结束程序。
[/quote]
无法输入任何东西,光标闪
9 楼
windy0will [专家分:2300] 发布于 2011-11-01 19:14:00
不好意思,C++我看得头痛。
10 楼
grace_lilian [专家分:0] 发布于 2011-11-01 19:16:00
[quote]不好意思,C++我看得头痛。[/quote]
哎。。。。555
我来回复