码迷,mamicode.com
首页 > 编程语言 > 详细

C++计算倒数的源码

时间:2019-04-17 16:41:31      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:ret   string   int()   opera   clone()   iostream   ring   int   names   

下边内容内容是关于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;
}

C++计算倒数的源码

标签:ret   string   int()   opera   clone()   iostream   ring   int   names   

原文地址:https://blog.51cto.com/14152780/2380198

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!