main.cpp:
_________________________________________________
#include <iostream>
#include "fonction.cpp" //使用雙引號將fonction.cpp檔含括進來
using namespace std;
extern void f(int); //宣告自訂函式mul
int a; //宣告全域變數a
int main(void)
{
f(5); //呼叫函式f並將回傳值儲存進變數a
cout<<"a = "<<a<<endl;
}
_________________________________________________
fonction.cpp:
_________________________________________________
extern int a; //加上extern修飾字
void f(int b)
{
a=b*b;
return;
}
fonction.cpp:
_________________________________________________
extern int a; //加上extern修飾字
void f(int b)
{
a=b*b;
return;
}
0 意見