당신이 선언하는 기능을 사용하기 전에 전화/니다. 당신이 한 선언 2 인수 버전 rectangle
기능 하지만 당신은 것을 잊을 선언하기 1 인수를 복용 버전입니다.
아래와 같이 추가하면 선언에 대한의 1 인자음에는 귀하의 프로그램이 작동하는(컴파일하고).
#include <iostream>
using namespace std;
//declare the function before main
int rectangle(int p, int l);
int rectangle(int p);//ADDED THIS DECLARATION
int main() {
cout << rectangle(3);
return 0;
}
//define the functions after main
int rectangle(int p) {
return p*p;
}
int rectangle(int p, int l) {
return p*l;
}
의 출력을 프로그램을 볼 수 있습니다 여기에.
대체 솔루션:
지 않는 경우 선언하고 싶은 각 기능에 별도로 그럼 당신은 단지 그들을 정의하기 전에 메인을 선언하는 대신 그들은 아래와 같습니다.
#include <iostream>
using namespace std;
//define the functions before main. This way there is no need to write a separate function declaration because all definition are declarations
int rectangle(int p) {
return p*p;
}
int rectangle(int p, int l) {
return p*l;
}
int main() {
cout << rectangle(3);
return 0;
}