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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

23The Terminal <strong>Expression</strong>sclass Literal : public TerminalExpr {public:Literal(double v) : _val(v) {}double eval() const { return _val; }private:const double _val;};class Variable : public TerminalExpr {public:Variable(double& v) : _val(v) {}double eval() const { return _val; }private:double& _val;};© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(45)last update: 11/7/2005 ,21:37The Non-Terminal <strong>Expression</strong>sclass BinaryExpr : public NonTerminalExpr {protected:BinaryExpr(const AbstractExpr* e1, const AbstractExpr* e2): _expr1(e1),_expr2(e2) {}virtual ~BinaryExpr (){ delete const_cast(_expr1);delete const_cast(_expr2);}const AbstractExpr* _expr1;const AbstractExpr* _expr2;};class Sum : public BinaryExpr {public:Sum(const AbstractExpr* e1, const AbstractExpr* e2): BinExpr(e1,e2) {}double eval() const{ return _expr1->eval() + _expr2->eval(); }};© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(46)last update: 11/7/2005 ,21:37

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

Saved successfully!

Ooh no, something went wrong!