11.07.2015 Views

Understanding C++ Expression Templates - Angelika Langer

Understanding C++ Expression Templates - Angelika Langer

Understanding C++ Expression Templates - Angelika Langer

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

28First attemptDefine the creator functions as overloaded operators:template BinaryExpr operator+(ExprT1 e1, ExprT2 e2){ return BinaryExpr (e1,e2); }An expression such as x+2 would evaluate toBinaryExpr (x,2)which is not exactly what we need. From just the type thecompiler cannot distinguish between a literal and a variableof type double. We need an binary expression that stores aVariable and a Literal expression internally.© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(55)last update: 11/7/2005 ,21:37Define variables as Variable expressions:double x; Variable v(x);cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!