Need help with resolving "unidentified reference to" error

Ok so I got this issue in my project I just can't for the life of me figure out. My compiler refuses to compile my program because of a variable i'm trying to declare pool as a type PoolClass so I can enter values from my driver (or main)into PoolClass (the class that is doing the calculating). As far as I'm seeing the syntax should be fine, I read on some threads that it might be a linker (based on similar issues) issue but everything seems to be in the right location (also checkmarking link or compile under options in code::blocks does NOT work, if anything it seems to make it worse...)

Here's what I have..

Main file (where I'm getting the error)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <cstdlib>
#include "PoolClass.h"
using namespace std;

void print(PoolClass& );

int main()
{
    PoolClass pool; //here I'm getting : unidentified reference to 'PoolClass::PoolClass(double, double, double, double, double, double)'
    double l;
    double w;
    double d;
    double fi;
    double fo;
    double wInPool;
// input pool dimensions and flow rate, and starting water
    cout << "Input pool data"<< endl;
    cout << "specify length"<< endl;
    cin >> l;

    cout << "specify width"<<endl;
    cin >> w;

    cout << "specify depth"<<endl;
    cin >> d;

    cout << "specify flow rate IN"<<endl;
    cin >> fi;

    cout << "specify flow rate OUT"<<endl;
    cin >> fo;

    cout << "specify water in pool (in gallons)"<< endl;
    cin >> wInPool;

    pool.set(l,w,d,fi,fo,wInPool);
}

void print(PoolClass& p1) // outputs the calculations
{
    cout << "Pool Data:"<<endl;
    cout << "Length: "<<p1.getLength()<<"feet"<< endl; //length output
    cout << "Width: "<<p1.getWidth()<<"feet"<< endl; // width output
    cout << "Depth: "<<p1.getDepth()<<"feet"<< endl; // depth output
    cout << "Amount of water in pool: "<<p1.getTotalWaterInPool()<<"gallons"<< endl; // water in pool output
    cout << "Fill Rate: "<<p1.getWaterFlowRateIn()<<"gal/hr"<< endl; // water flow rate in output
    cout << "Drain Rate: " <<p1.getWaterFlowRateOut()<<"gal/hr"<< endl; // water flow rate out output
    cout << "Water needed to fill the pool: "<<p1.getTotalWaterInPool()<<"gallons"<< endl; // water needed to fill pool output
    cout << "Time needed to fill the pool: "<<p1.timeToFillThePool()<<"feet"<< endl; // time needed to fill pool output
    cout << "After filling pool to capacity, amount of water in pool is: "<<p1.getTotalWaterInPool()<<"gallons"<< endl; // amount of water in pool output
    cout <<"Time needed to drain the pool completely:"<<p1.timeToDrainThePool()<<"minutes"<<endl; // time needed to drain pool output
    cout <<"Amount of water left after draining half the pool:"<<p1.getTotalWaterInPool()<<"gallons"<< endl; // water left after draining pool output
    cout << "Time needed to fill the pool if it is half full: " <<p1.timeToFillThePool()<<"gallons"<< endl; // time needed to fill pool if it is half full
    cout << "Amount of water after adding water an additional 3 hours" <<p1.getTotalWaterInPool()<<"gallons"<< endl; // amount of water after adding water output
    cout <<"Time needed to drain half the pool:" <<p1.timeToDrainThePool()<<"minutes"<<endl; // time needed to drain half the pool output
}

PoolClass Implementation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

#include <iostream>
#include "PoolClass.h"

using namespace std;

void PoolClass::set(double l, double w, double d, double fi, double fo, double wInPool) // sets the input variables
{


    l = length;
    w = width;
    d =  depth;
    fi = waterFlowInRate;
    fo = waterFlowOutRate;
    wInPool = amountOfWaterInPool;


    if (l <= 0 or w <= 0 or d <= 0 or fi <= 0 or fo <= 0 or wInPool < 0)
    {
        cout <<"invalid entry, enter valid entry"<< endl;
    }
}
void PoolClass::addWater(double time, double rate) // calculates the amout of water added given the time and rate
{
    if( (time * rate) + amountOfWaterInPool > poolTotalWaterCapacity())
    {
       cout << "overfill, water level defaulted to total capacity"<< endl;
       amountOfWaterInPool = time * rate;
    }
    else
    {
        amountOfWaterInPool =(time * rate) + amountOfWaterInPool;
    }
}
void PoolClass::drainWater(double time, double rate) // calculates the amount of water subdracted after the prescribed amount of time and the rate
{

    if (amountOfWaterInPool - time * rate < 0)
    {
        cout << "the pool is empty"<< endl;
        amountOfWaterInPool = 0;
    }
    else
    {
        amountOfWaterInPool -= time * rate;
    }
}
double PoolClass::poolTotalWaterCapacity() // calculates the total pool capacity based on given dimensions
{
    return length*width*depth;
}
int PoolClass::timeToFillThePool() // calculates time needed to fill the pool
{
    double waterdifference;
    waterdifference = poolTotalWaterCapacity() - getTotalWaterInPool();

    return waterdifference/ waterFlowInRate;
}
//double PoolClass::timeToFillThePoolHALF() // ignore this function, still working on it

int PoolClass::timeToDrainThePool() // calculates time needed to drain pool
{
    return amountOfWaterInPool / waterFlowOutRate;
}
double PoolClass::waterNeededToFillThePool()  // calculates the amount of water needed to fill the pool
{
double WaterNeededToFillThePool = poolTotalWaterCapacity() - amountOfWaterInPool;
return WaterNeededToFillThePool;
}

double PoolClass::getLength() // gets the length of the pool from the private variable
{
    return length;
}
double PoolClass::getWidth() // gets the width of the pool from the private variable
{
    return width;
}
double PoolClass::getDepth() // gets the depth of the pool from the private variable
{
    return depth;
}
double PoolClass::getWaterFlowRateIn() // gets the water flow rate in
{
    return waterFlowInRate;
}
double PoolClass::getWaterFlowRateOut() // gets the flow rate out
{
    return waterFlowOutRate;
}
double PoolClass::getTotalWaterInPool() // gets the total water in pool
{
    return amountOfWaterInPool;
}
void PoolClass::setLength(double l) // sets the length of the pool
{
   length = l;
}
void PoolClass::setWidth(double w) // sets the width of the pool
{
    width = w;
}
void PoolClass::setDepth(double d) // sets the depth of the pool from private
{
    depth = d;
}
void PoolClass::setWaterFlowRateIn(double fi) // sets the flow rate/in of the pool
{
    waterFlowInRate = fi;
}
void PoolClass::setWaterFlowRateOut(double fo) // sets the flow rate/out of the pool
{
    waterFlowOutRate = fo;
}

Header File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class PoolClass
{
public:
    void set(double l, double w, double d,
            double fi, double fo, double wInPool);
    
    void setLength(double l);
    void setWidth(double w);
    void setDepth(double d);
    void setWaterFlowRateIn(double fi);
    void setWaterFlowRateOut(double fo);

    void addWater(double time, double rate);
    

    void drainWater(double time, double rate);
    
    double poolTotalWaterCapacity();
   
    double getLength();
    double getWidth();
    double getDepth();
    double getWaterFlowRateIn();
    double getWaterFlowRateOut();
    double getTotalWaterInPool();

    int timeToFillThePool();
   
    int timeToDrainThePool();
   
    double waterNeededToFillThePool();
   
    //int timeToDrainThePoolHalf();


    PoolClass(double l = 0, double w = 0, double d = 0,
            double fi = 0, double fo = 0, double wInPool = 0);
   
private:
    double length;    // in feet
    double width;     // in feet
    double depth;     // in feet
    double waterFlowInRate;    // in gallons per minute
    double waterFlowOutRate;   // in gallons per minute
    double amountOfWaterInPool;   // in gallons
};

Last edited on
closed account (48T7M4Gy)
Where is the PoolClass constructor? All I can see in the jungle is a set method.
It's on line 36/37 in the header part

It's this guy:
1
2
PoolClass(double l = 0, double w = 0, double d = 0,
            double fi = 0, double fo = 0, double wInPool = 0);
Last edited on
closed account (48T7M4Gy)
If that's the constructor how are length. width, depth and all the other private attributes of the Pool set?
how are they private attributes?(not really asking how, just saying is that what you mean) If i understood you correctly, they are supposed to be an indirect way of acessing the private variables (referring to l,w,d and other stuff) the intention is that they are to be stored in the private variables once the set function takes what I put in.
Last edited on
closed account (48T7M4Gy)
how are they private attributes?


The attributes I am referring to are prefixed by the statement private:

PoolClass(double l = 0, double w = 0, double d = 0, double fi = 0, double fo = 0, double wInPool = 0); is incorrect for two reasons

1. the various parameters are not used.
2. if you don't want to use them then the constructor is PoolClass(){}; mine compiles, yours regrettably doesn't because the machine hasn't got a clue what a PoolClass is. That's what the error message is about. :)
Last edited on
oh ok, so we're on the same page then. Yeah, i know that's what i'd want to use if i'm using the default constructor, but i need to initialize those variables so it's not really an option i'd want to go with. plus they are used in the set function so i can store my input from outside the class and into the private variables.

1
2
3
4
5
6
7
8
void PoolClass::set(double l, double w, double d, double fi, double fo, double wInPool) // sets the input variables
{
    l = length;
    w = width;
    d =  depth;
    fi = waterFlowInRate;
    fo = waterFlowOutRate;
    wInPool = amountOfWaterInPool;
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
void PoolClass::set(double l, double w, double d, double fi, double fo, double wInPool) // sets the input variables
{
    l = length;
    w = width;
    d =  depth;
    fi = waterFlowInRate;
    fo = waterFlowOutRate;
    wInPool = amountOfWaterInPool;


I know that's what you're doing but its wrong. It doesn't work. For a start it should be
length = l etc, you have them the wrong way around. l, w etc are what type in the class??

You seem to not understand that you must construct an object first even if you want to set the properties/attributes for whatever reason later on. The bottom line though is, if you don't construct an object you are doing it into the wind if you want to set the imagined objects properties.
Last edited on
Ok I see, sorry about all that I didn't catch your edit when I first read yours. once i did that it compiled again. I just didn't want to mess with it if i could help it since it was provided by my instructor, plus i didn't think I could use the default constructor if i wanted to use those variables. I'm leaving it at what you suggested for now. while I get some of the other stuff to work.

Did you get an output on your end? I put in all 0's to see if the set "audit" system catches that, and it at least works to that point. I tried hardcoding some numbers in a few spots like set just to see if i can force anything through, no luck yet though. Got any suggestions on why print isn't providing an output from my functions?
closed account (48T7M4Gy)
yep, I got plenty of output all based on getting the variables around the right way and letting the program run with the values you gave them in main. Sounds like your instructor might be a bit dodgy.

print doesn't work because you missed it as the last line in main.

print( pool); was the line I added, if I remember correctly.

You've got a blooper too in the time it takes to fill. The units are time not feet. Cruel, isn't it ? :)

Good luck with it though - cheers.
Great news! It's fixed. Now i have an output, just have to fix how i have the numbers, nothing i can't do though. Yeah I got a bit lazy on the units and just copied and pasted the ends there, so that one fell though the cracks. Appreciate the help and putting up with me lol. yeah I definitely got a lot to learn on my syntax, but feedback always goes a long way (in my case anyway) :)
closed account (48T7M4Gy)
:)
Topic archived. No new replies allowed.