As discussed in section 12.2.5, type field codes that are less versatile, error-prone, Less maintenance, and less maintenance than the equivalent function using virtual functions and polymorphism.
As a brief example, how will one type of field be used here:
Zero print (Konst shape & amp; s) {switch (S.Prop ) {Case Size :: Triangle: Cot & lt; & Lt; "Triangle" & lt; & Lt; Endl; Case Size: Square: Cot & lt; & Lt; "Square" & lt; & Lt; Endl; Default: cout & lt; & Lt; "None" & lt; & Lt; Endl; }}
Obviously, this is a nightmare in the form of adding a new type of shape and a dozen similar tasks will be error-prone and taxing.
Despite all these deficiencies and all the examples mentioned in TC + PL, where such implementation (use of a type of field) is a better solution than the use of language features of virtual work? Or should this practice be black listed as pure evil?
Real examples will be given priority for real people, but I still would be interested in responsive examples. Also, have you ever seen it in the output code (even if the virtual task would have been easier)?
When you "know" you have a very specific, small, continuous type of set It may be easy to decode them in this way. Of course, you are not stable and there are variables, so at some point you may have to rewrite the whole thing.
This is more or less, many techniques used for unions with discrimination.
For example, if I was implementing a library, then I knew that each value can only be an object, array, string, integer, boolean or tap - imagine any other does not allow.
Comments
Post a Comment