我想在C++中創建一個非常簡單的函數,但是我不斷收到「鏈接錯誤」。C++中的函數幫助
我的代碼:
#include <iostream>
using namespace std ;
int fun(int,int);
main(){
int width,height,w,h,mult;
cin>>width;
cin>>height;
mult = fun(width,height);
int fun(int w,int h);{
w * h ;
}
cout << mult ;
}
錯誤:
[Linker error] undefined reference to `fun(int, int)'
ld returned 1 exit status
您的樂趣實施是在錯誤的範圍內,你需要把它的主要之外。 – Vinzenz 2010-10-10 21:14:55
你也試圖在'main'裏面定義函數'fun'。嘗試在'cout << mult;'out'main'之前移動代碼。 – birryree 2010-10-10 21:18:06
是爲了實現樂趣而調用fun之後的代碼塊的意圖?它幾乎看起來像試圖在C++代碼中使用委託(C#)...有沒有像我不知道的東西?有 – 2010-10-10 21:20:08