Skip to main content
added 692 characters in body
Source Link
Martin Maat
  • 18.6k
  • 3
  • 33
  • 59

Inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

Edit: Apparently, as pointed out by Kevin, the particular limitation described above does not apply to C++ (it is valid for C#). You would still want to consider whether all the operations you are going to implement will be meaningful for integers and floating type numbers alike though. This may be hard to foresee. I mean, the "smart" solution may bite you in the arse later.

If for instance, if you needed to create an operation that will give you the average value in a column, that would require you to apply some rounding logic if you were dealing with integers. But not if you were dealing with floats. You would not be so happy with your fancy template solution at that point.

Inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

Inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

Edit: Apparently, as pointed out by Kevin, the particular limitation described above does not apply to C++ (it is valid for C#). You would still want to consider whether all the operations you are going to implement will be meaningful for integers and floating type numbers alike though. This may be hard to foresee. I mean, the "smart" solution may bite you in the arse later.

If for instance, if you needed to create an operation that will give you the average value in a column, that would require you to apply some rounding logic if you were dealing with integers. But not if you were dealing with floats. You would not be so happy with your fancy template solution at that point.

deleted 3 characters in body
Source Link
Martin Maat
  • 18.6k
  • 3
  • 33
  • 59

In inheritanceInheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

In inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

Inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.

Source Link
Martin Maat
  • 18.6k
  • 3
  • 33
  • 59

In inheritance does not apply. You could do it with a so called template class but I would not recommend it. If T is a value type like in your case you typically want to perform arithmetic operations on it and these do not work well with T. So you would be better of treating integer tables as different from float tables and have different, dedicated and independent classes for them. That only share methods names for readability/consistency.