您好,登錄后才能下訂單哦!
下邊內容內容是關于C++計算倒數的的內容,應該是對各位有較大好處。
#include <iostream>
using namespace std;
class Var;
class Base {
public:
virtual ~Base() {};
virtual ostream &print(ostream &o) const = 0;
};
ostream &operator<<(ostream &o, const Base &e) { e.print(o); return o; }
class Int : public Base {
const int n;
public:
Int(int m) : n(m) {}
~Int() {}
ostream &print(ostream &o) const { return o << n; }
};
class Var : public Base {
const string var;
public:
Var(string v) : var(v) {}
~Var() {}
ostream &print(ostream &o) const { return o << var; }
};
class Plus : public Base {
public:
~Plus() { delete e1; delete e2; }
ostream &print(ostream &o) const
};
class Times : public Base {
public:
~Times() { delete e1; delete e2; }
{ return new Plus(new Times(e1, e2->d(v)), new Times(e1->d(v), e2)); }
};
class Expr {
public:
};
const Expr operator+(const Expr e1, const Expr e2)
{ return Expr(new Plus(e1.e->clone(), e2.e->clone())); }
{ return Expr(new Times(e1.e->clone(), e2.e->clone())); }
ostream &operator<<(ostream &o, const Expr e) { return o << e.e; }
int main() {
Var vx("x"), va("a"), vb("b"), vc("c");
Expr x(&vx), a(&va), b(&vb), c(&vc);
return 0;
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。