不能解决函数调用!
来源:互联网 发布:mac上电话轰炸 编辑:程序博客网 时间:2024/06/10 01:18
然而,我们更喜欢我们的参数,因为它允许您了解什么功能参数只是通过看原型。否则,你必须找到实际的函数定义。
Tip: You can easily create function prototypes by using copy/paste on your function declaration. Don’t forget the semicolon on the end.
提示:您可以使用复制/粘贴功能声明来轻松创建功能原型。别忘了在后面的分号。
Forgetting the function body
忘记了身体
One question many new programmers have is: what happens if we forward declare a function but do not define it?
许多新程序员都有一个问题是:如果我们向前声明一个函数,但不定义它,会发生什么?
The answer is: it depends. If a forward declaration is made, but the function is never called, the program will compile and run fine. However, if a forward declaration is made, the function is called, but the program never defines the function, the program will compile okay, but the linker will complain that it can’t resolve the function call.
答案是:这取决于。如果有一个向前声明,但该函数是从未调用的,程序将编译和运行良好。但是,如果一个向前声明,该函数被调用,但程序没有定义函数,程序将编译好,但连接器会抱怨它不能解决函数调用。
Consider the following program:
考虑以下程序:
#include <iostream> int add(int x, int y); // forward declaration of add() using function prototype int main(){ using namespace std; cout << "The sum of 3 and 4 is: " << add(3, 4) << endl; return 0;}
你可以看到,程序编译好的,但是它没有在链接阶段(int,int,int加)没有定义。
Other types of forward declarations
其他类型的前瞻性声明
Forward declarations are most often used with functions. However, forward declarations can also be used with other identifiers in C++, such as variables and user-defined types. Other types of identifiers (e.g. user-defined types) have a different syntax for forward declaration.
正向声明是最常用的函数。然而,前向声明也适用于C++的其他标识符,如变量和用户自定义类型。其他类型的标识符(如用户定义的类型)有一个不同的语法声明。
We’ll talk more about how to forward declare other types of identifiers in future lessons.
在今后的课程中,我们将讨论如何向前声明其他类型的标识符。
Declarations vs. definitions
声明与定义
In C++, you’ll often hear the words “declaration” and “definition” used. What do they mean? You now have enough of a framework to understand the difference between the two.
在C++中,你经常会听到“宣言”和“定义”。他们是什么意思?你现在有足够的框架来理解两者之间的差异。
A definition actually implements or instantiates (causes memory to be allocated for) the identifier. Here are some examples of definitions:
定义实际实现或实例化(导致内存被分配的标识符)。下面是一些定义的例子:
int add(int x, int y) // defines function add(){ return x + y;} int x; // instantiates (causes memory to be allocated for) an integer variable named x
- 不能解决函数调用!
- MySql不能调用函数
- JS不能调用clear函数
- 【win32 app调用html方法】解决VS2008中CHtmlView函数OnBeforeNavigate2不能禁止跳转的BUG
- Ubuntu下使用make编译c文件,不能调用sin cos 等函数问题的解决
- 解决mysql不能创建函数
- 解决mysql不能创建函数
- 构造函数不能调用构造函数
- static 函数 不能为外部文件调用
- 中断函数中不能调用ioremap()!!!!!!!
- 调用函数的时候不能禁用按钮
- 在构造函数里不能调用shared_from_this()
- 构造函数/析构函数不能调用虚函数
- 函数指针不能直接调用类的成员函数
- WebView 中的javascript函数不能调用java函数的问题
- C#中构造函数不能调用构造函数?
- 为什么析构函数中不能调用虚函数
- 为何不能调用含有selection screen的程序 -- 已解决
- android canvas\paint\path简单使用(自定义view必学)
- genymotion启动不了的解决方法
- php函数之func_get_args()、func_get_arg()与func_num_args()
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- swift开发笔记28 使用系统自带地图
- 不能解决函数调用!
- 判断 fir-clia 是否安装
- HDU-4568 Hunter (Dijkstra&&状压DP)
- shell之traceroute命令
- css选择器的优先级
- GreenHandX1h 4.1 questions
- React 构成理解
- Balloon Comes!
- Linux驱动基础:msm平台,modem等framework加载