C ++は別のcppファイルのcppファイルで定義された関数を使用します
コンソールプロジェクトを作成する
例としてdevを取り上げ、[File] [New] [Project]に新しいコンソールプロジェクトを作成します。
ヘッドファイル
新しいファイルを追加し、関数を使用することを示すステートメントを入力して、.hファイルとして保存します。
int add(int a,int b);
cppファイル
.hで宣言された関数を定義し、.cppファイルとして保存します。
#include<iostream>
#include"chen.h"//不要忘记这个
int add(int a,int b)
{
return a + b ;
}
main.cpp
メイン関数で関数を呼び出す
#include <iostream>
#include "chen.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
cout << add(3,5) << endl;
return 0;
}
演算結果: