M
Maarten Kronenburg
Marteen,
If I understand correctly, the hash value is a function of the string
itself. In that case for the derived overridden member function add (with
argument ref base class) there would be no problem, because adding the
string with hash would mean first adding the strings themselves, and after
that recomputing the hash value, no matter if the argument was base or
derived. For the binary operator+ returning a base class object is also no
problem, because after that the operator= is called which calls the derived
overridden member function assign, where the hash is recomputed after the
strings are assigned. In other words, when the hash value is just a function
of the string values, it doesn't matter if they are sliced off, because they
can be recomputed. Unless you want to recompute the hash values from the
argument hash values, and not from the resulting string.
Regards, Maarten.
The design you provide necessates that hash be performed outside the
class and be served as a parameter in the constructor. But in my
design, the hash string class itself should provide for computation of
hash. In essence by choosing a hash_string over a char_string , the
user is implying that i have a lot oc comparisons to do hence compare
the strings using the hash value. Usabilitry wise it would behave
identically to char_string. I had a desing using policy classes that
waorked , but the change in design necessated from the fact that a
common interface a.k.a a non-template base_string generic class would
be needed . Now i'm stuck with this overriding of virtual class wich
returns by value paradox. I'll go thrrough the NVI design pattern
hopefully to pick up some clue
If I understand correctly, the hash value is a function of the string
itself. In that case for the derived overridden member function add (with
argument ref base class) there would be no problem, because adding the
string with hash would mean first adding the strings themselves, and after
that recomputing the hash value, no matter if the argument was base or
derived. For the binary operator+ returning a base class object is also no
problem, because after that the operator= is called which calls the derived
overridden member function assign, where the hash is recomputed after the
strings are assigned. In other words, when the hash value is just a function
of the string values, it doesn't matter if they are sliced off, because they
can be recomputed. Unless you want to recompute the hash values from the
argument hash values, and not from the resulting string.
Regards, Maarten.