Where to check for conditions?

Hello All! I am a bit confused on where to check for conditions. This is a separate class that is combined with a base class "Package" and it other sub classes.

or would I have to do a for loop?



1
2
3
4
5
6
7
8
9
10
11
12
  Package P(senderN, senderA, senderC, senderS, senderZIP, recipN, recipA, recipC, recipS, recipZIP, L, D, W, C, insure);

  if(P.getWeight()<0 || P.getInsuranceFee()<0 || P.getCost()<0)
    {
      cout << "\nInvalid Entry\n";
    }
  else
    {
      packages.push_back(P);
    }



This is what I have so far and it compiles and runs and everything, but is this correct?
Do I have to go through a for loop to get every single one? but I feel like this is correct? Idk please give some feedback
Last edited on
it's better to check these conditions through the Package ctor and ensure that only Package objects with valid weight, insuranceFee and costs are instantiated
Topic archived. No new replies allowed.