From: moreno_news@mailinator.com   
      
   On 11-07-11 01:31 PM, Daniel Krügler wrote:   
      
   >> [ ... ]   
   >> size(). Here's the exact output:   
   >>   
   >>> expression_templates.c++: In constructor ‘VecDifference>> E2>::VecDifference(const VecExpression&, const VecExpression&)   
   >>> [with E1 = Vec, E2 = Vec]’:   
   >>> expression_templates.c++:91:35: instantiated from ‘const   
   >>> VecDifference operator-(const VecExpression&, const   
   >>> VecExpression&) [with E1 = Vec, E2 = Vec]’   
   >>> expression_templates.c++:103:21: instantiated from here   
   >>> expression_templates.c++:66:5: error: no matching function for call to   
   >>> ‘VecExpression::size() const’   
   >>> expression_templates.c++:66:5: error: no matching function for call to   
   >>> ‘VecExpression::size() const’   
   >   
   > The Wikipedia example is indeed broken, but are you sure that you quoted   
   > the complete compiler message?   
      
   Yes --- however, I omitted some details about the code that I   
   was really compiling; for example, yes, I did of course #include   
    and surely enough, put using namespace std; (I figured   
   that would be implicitly assumed)   
      
   The "unintentional" mistake was that I did remove the typename   
   E::size_type and the like, and replaced everything that was the   
   type for a subscript with size_t, and everything that was the   
   value, I used double for its type.   
      
   I remembered this detail some 3 or 5 minutes after posting :-)   
      
   I see two defects in the code:   
   >   
   > a) Within the declarations of CRTP base class VecExpression you cannot   
   > refer to typedefs of the derived type E directly. This is so, because at   
   > the point, where E derives from VecExpression, VecExpression needs   
   > to be a complete type, but it is not, because it refers to the yet   
   > incomplete type E.   
      
   I see --- I thought that it would be ok, the same way as casting   
   to const E & in operator[] is; but I now see the difference: E &   
   is not at all the same as E::something ... E & only requires   
   knowing *of* E, whereas E::xxx requires knowing E.   
      
   > b) I don't see any reason for the usage of the 'template' prefix within   
   > the VecDifference constructor assertion:   
   >   
   > assert(u.template size() == v.template size());   
      
   Actually, this was the error, as CornedBee pointed out; when I   
   remove it, it compiles (that, in addition to the above, but then,   
   I had already replaced E::size_type with size_t and E::value_type   
   with double).   
      
   That means that Wikipedia's example would require the additional   
   modification (CornedBee already removed the template detail in the   
   calls to .size() in the assert) --- but I'm reluctant to change it   
   to "hardcoded" types, like I did in my working sample... I guess   
   traits, as you suggest, would be a good approach.   
      
   Thanks,   
      
   Carlos   
   --   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|