C++ - I'm supposed to compute the area of two shapes by overloading the area() function and the way I want to solve the problem is by passing the values of the constants as default arguments to both the functions, as the problem statement asks me to write one for each shape. But when I try to compile the code, I get the error message "undefined reference" for both the functions. Now I could straight away look it up on the web, but I want to know where am I going wrong.
I'm using Ubuntu 16.04.
#include<iostream>
#include<math.h>
using namespace std;
double area(int r, float pi=3.14); //prototype for calculating the area of circle
double area(int l, int h, float a=0.5); //prototype for area of triangle
int main()
{
int l, r, h;
cout<<"Enter the radius of the circle\n"; //accepting radius
cin>>r;
cout<<"Enter length of one side and height of triangle\n"; //accepting length and height
cin>>l>>h;
cout<<"Area of circle is = "<<area(r)<<"\n\n";
cout<<"Area of triangle is = "<<area(l, h)<<"\n";
}
double area(int r) //declaration for circle, passing radius accepted and pi as default parameter
{
float pi;
double z = r*r*pi;
return z;
}
double area(int l, int h) //declaration for triangle passing l and b accepted, and 0.5 as default parameter
{
float a;
double z = l*h*a;
return z;
}
the error message: