在:http://www.learncpp.com/cpp-tutorial/19-header-files/
提到以下内容:
add.cpp:
int add(int x, int y)
{
return x + y;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <iostream>
int add(int x, int y); // forward declaration using function prototype
int main()
{
using namespace std;
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我们使用了前向声明,以便编译器在编译时知道"
add"是什么main.cpp.如前所述,为要在其他文件中使用的每个函数编写前向声明可能会很快变得乏味.
你能进一步解释" 前瞻性宣言 "吗?如果我们在main()函数中使用它会有什么问题?
在Java文件中拥有多个类的目的是什么?我是Java新手.
编辑: 这可以通过在公共类中创建内部类来实现,对吧?
我正在编写一个多RootViewController视图应用程序,它利用一个叫做在视图之间切换的类.
在我的MyAppDelegate标题中,我创建了一个被RootViewController调用的实例rootViewController.我已经看过这样的例子,其中@class指令被用作"前向类声明",但我不太确定这意味着什么或完成了什么.
#import <UIKit/UIKit.h>
@class RootViewController;
@interface MyAppDelegate
.
.
.
Run Code Online (Sandbox Code Playgroud)