Reputation: 1545
Header file for the following error : undefined reference to `swimmingPool::timeNeeded(int)'
I am making some trivial error in the code but not able to make out what.Relatively new to the language.Please help !!
#include<iostream>
#include<cstdio>
#include "swimmingPool.h"
using namespace std;
int main()
{
cout << "Pool Data: " << endl;
swimmingPool p(30,15,10,0,0);
int rate_in;
cout << " Length: " << p.length << endl;
cout << " Width: "<< p.width << endl;
cout << " Depth: "<< p.depth << endl;
cout << " Total water in the pool: " << p.water_initially <<endl;
cout << "To completely fill the pool" << endl;
cout << " Enter water fill in rate: ";
cin >> rate_in;
cout<< endl;
cout << endl;
cout << "Time to fill the pool is approximately: " << p.timeNeeded(rate_in)/3600 << " hours and "<<
p.timeNeeded(rate_in)%60<< " minutes."<<endl;
return 0;
}
/**********************************************************************************/
/******************** swimmingPool.h **********************************************/
#ifndef __IH__
#define __IH__
class swimmingPool{
public:
int length;
int width;
int depth;
int rate_out;
int water_initially;
int waterNeeded();
int timeNeeded(int in);
swimmingPool(int a,int b, int c, int d,int e){}
};
#endif
/********************************************************************************/
/******************************** swimmingPoolImp.cpp ****************************/
#include<iostream>
#include<cstdio>
#include "swimmingPool.h"
swimmingPool::swimmingPool(int a,int b, int c, int d,int e) //IT has five parameters for length/breadth/height/water_initially/rate_out.Rate to be taken input from user.
{
length = a;
width = b;
depth = c;
rate_out = d;
water_initially = e;
}
int swimmingPool::waterNeeded()
{
return( length*width*depth - water_initially)*7.48; //conversion factor
}
int swimmingPool::timeNeeded(int rate_in)
{
if(rate_in > rate_out)
{
return (( waterNeeded() / (rate_in - rate_out))*60);
}
else
{
return (( waterNeeded() / (rate_out - rate_in))*60);
}
};
Upvotes: 0
Views: 373
Reputation: 816
Resolve multiple definitions of the constructor (one in header and other in cpp file)
swimmingPool(int a,int b, int c, int d,int e){} // **this makes it a definition and not just declaration**
swimmingPool::swimmingPool(int a,int b, int c, int d,int e) //IT has five parameters for length/breadth/height/water_initially/rate_out.Rate to be taken input from user.
{
length = a;
width = b;
depth = c;
rate_out = d;
water_initially = e;
}
Change swimmingPool(int a,int b, int c, int d,int e){}
to swimmingPool(int a,int b, int c, int d,int e);
Upvotes: 1
Reputation: 86
The error message in the category "undefined reference to..." generally means that the function, compiled or otherwise was not linked into your executable.
First, make sure that the object file for swimmingPool.cpp (swimmingPool.o or or windows, swimmingPool.obj) was linked into your program.
If you've confirmed that, then it's possible that your make tool forgot to recompile swimmingPool.cpp after you added timeNeeded, and therefor that object file is out of date. You should recompile swimmingPool.cpp if that's the case.
The specific commands necessary to do this depends on your toolchain.
Also, your functions are not "const-correct" and you should look that up soon as you learn.
Upvotes: 1