function-declaration - 如果我这样声明函数,为什么它不起作用?
问题描述
我在 main fn 之前首先声明了 'GuGuDan' fn,但它显示错误消息'隐式声明函数'GuGudan' 在 C99 中无效'并且不起作用。所以我试图找到另一种解决方案,并发现如果我在“WhatToPrint”fn 中声明它就可以工作。
#include <stdio.h>
void GuGuDan(int, int);
void WhatToPrint(int, int);
...
void WhatToPrint(int x, int y){
void GuGudan(int, int);
// why must I declare GuGuDan fn in WhatToPrint fn?
...
}
解决方案
在声明中,您只指定输入的数据,但在定义中,您需要为其提供变量。所以如果你像下面那样做它应该可以工作。
#include <stdio.h>
void GuGuDan(int, int); //this is the declaration
void WhatToPrint(int, int);
...
void GuGudan(int x, int y){
// This way your GuGudan function will work
...
}
void GuGudan(int x, int y){
// This way your GuGudan function will work
...
}
推荐阅读
- algorithm - 在没有联合查找数据结构的情况下实现 CCL(连接组件标签)算法?
- python-3.x - 我无法保存列表
- javascript - How to destructure an object without one key
- python - 如何使用 python 和 jq 从多个值中选择 json 值
- delphi - 函数在数组和整数比较上返回false?
- python - 通用接口/ C++ 模板等效的 Python 类型提示
- java - Java 测验 - 正确时不接受用户输入
- java - JPanel 线程在主应用程序上的 jdbc 操作期间冻结
- api - Flask API run on Docker but can't access
- html - 如何修复 #intro 的“滑入式”cssanimation 以正常工作?