Functions operate on whole types. The function open_door() operates on a whole door. The function fix_door_handle() operates on a door handle, not on a door handle that has specifically been removed from a door (some door handles have never been installed on doors).
I understand your concern that passing the whole structure isn't necessary. In this case you're absolutely right, isValidDate() should probably only take a string (it depends on whether the logic of isValidDate() is intrinsically tied to the fact that the date is part of a ty_venta). However, just because a function operates only on certain members of a type isn't by itself reason enough to have the function take the types of those members.
For example, suppose you have the type
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
struct InventoryItem{
string name;
double price;
int quantity
};
InventoryItem increment_quantity(InventoryItem ii){
InventoryItem ret = ii;
ret.quantity++;
return ret;
}
//usage:
item = increment_quantity(item);
|
You might argue, following your previous reasoning, that it would be better to just do
item.quantity++;
.
In general, you'd be wrong. If the implementation of InventoryItem were to change the nature of quantity, you'd either have to find all places where the value is changed manually, or get clever with operator overloading. Neither are exactly nice solutions.
Anyway, more to the point of your question, your modification is correct if you make this change:
if(
rVenta.sFech == "0")
sFech is, from the point of view of isValidDate(), not part of any struct. It's just some random string floating out there.
Soon enough you'll learn that in reality, these "optimizations" are irrelevant. There are ways of passing data of any size without any kind of performance hit.