溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

C++計(jì)算倒數(shù)的源碼

發(fā)布時(shí)間:2020-08-06 21:25:04 來(lái)源:網(wǎng)絡(luò) 閱讀:832 作者:嚇了一跳哦 欄目:網(wǎng)絡(luò)安全

下邊內(nèi)容內(nèi)容是關(guān)于C++計(jì)算倒數(shù)的的內(nèi)容,應(yīng)該是對(duì)各位有較大好處。

#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;
}

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI