Need help with classes

Solved
Last edited on
2 things I see:

Main is a function, a function of type int.
An integer function should have a return statement.

2nd thing I see is in line 98... CondoList must be initialized with a constructor if I'm not mistaken...
Solved
Last edited on
The stated purpose of the recordFood function (obtained from the comment in code) is to "record amount of food currently being contained by all the condo's and record it for later." How does the argument received by the function further that cause?

1
2
3
4
double checkFoodSupply::recordFood(T nT) {
    for (auto & condo : CondoSupply)    // for each condo in CondoSupply
        records.push_back({ 1, condo.foodSupply() });       // 1 is a placeholder for a more useful value.
}


Note that nT is not used, because I have no idea what it is supposed to represent. Feeding the function a time to be used rather than the placeholder might make sense.

[edit: I changed line 81 to be: std::vector<foodAmount> records; since what you had was a syntax error.]
Last edited on
Solved
Last edited on
Does it matter if my function is a double but returns nothing?

Yes. If you promise to return a value, you're required to return a value.


Why is line 81 a syntax error? Doesn't the private function have to differ from the public, and doesn't the const have to stay for both?

Hmm. Well, I have to admit I didn't attempt to compile it as-is, because it didn't make sense for that to be a function. Especially, given the attempted implementation of your recordFood method.


Should I also have removed the & symbol before my CondoSupply in the private?

I'm not sure what you're referring to here.


For the next part, if I want to return the record of food to someone, can I directly return the vector or do I need to return every element of it, like you do with arrays?
1
2
std::vector<foodAmount> records() const{
return records;}

That is perfectly fine.
Solved
Last edited on
I meant the pass by reference symbol, and I also removed the const

It was fine as it was, but either way works.


All I want to do is store the amount of food per time(nT) in the vector, and the double will return the amount of food at that specific time.
1
2
3
4
5
6
7
8
9
10
double checkFoodSupply::recordFood(T nT) {
    double total_supply = 0.0;
    for (auto & condo : CondoSupply)    // for each condo in CondoSupply
    {
        double supply = condo.foodSupply();
        total_supply += supply;
        recordsP.push_back({ nT, supply });  // or whatever you're calling the data member now.
    }
    return total_supply;
}


Solved
Last edited on
Topic archived. No new replies allowed.