c++ - how do traits classes work? -


I'm reading Scott Meyer '' The symptom is talking about classes, I came to understand that the compilation time I need them to determine the type of object, but I did not understand what these classes really do. (Technically speaking)

Perhaps you are expecting some kind of magic which makes the type properties Work should be disappointed, in that situation, there is no magic. Type Properties are Manually defined for each type

For example, consider iterator_traits , which can be used for typefuffs (e.g. value_type ).

By using them, you can

  iterator_traits & lt; Vector & lt; Int & gt; :: Iterator & gt; :: value_type x; Iterator_traits & lt; Int * & gt; :: value_type y; // `x` and 'y` are type int   

but for this to work, actually in an obvious definition somewhere & lt; Iterator & gt; is in the header, which reads something such as this:

  template & lt; Typename T & gt; Straight iterator_traits & lt; T * & gt; {Type didif t value_type; // One ?? |};   

This is the type of iterator_traits for the types of partial specialization T * , that is, some common types of Signal

In the same vein, iterator_traits are specific to other iterators, e.g. typename vector & lt; T & gt; :: Iterator .

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -