简单表达式求值

标题: 2、操作符重载 时 限: 1000 ms 内存限制: 10000 K 总时限: 3000 ms 描述: 定义有理数Rational类。成员变量:分子int Up; 分母 int Down。 完成成员函数:Rational operator + (int num); Rational operator + (Rational r); Rational operator * (int num); Rational operator * (R...
c++ | 2011-10-25 21:29 | 阅读 907 次 | 评论 0 条

关于常量成员函数

使用const关键字进行说明的成员函数,称为常成员函数。只有常成员函数才有资格操作常量或常对象,没有使用const关键字说明的成员函数不能用来操作常对象。常成员函数说明格式如下: <类型说明符> <函数名> (<参数表>) const; 其中,const是加在函数说明后面的类型修饰符,它是函数类型的一个组成部分,因此,在函数实现部分也要带const关键字。下面举一例子说明常成员函数的特征。 例子:class Coo{public:Coo() : a(0){}int getA() const //常量成员函数{++a; //编译错误return this->a;}private:mutab...
c++ | 2011-10-12 23:24 | 阅读 1092 次 | 评论 0 条

关于抽象类的派生与运算符的重载测试源码

#include <iostream>using namespace std;#define PI 3.14159class shape{ public: virtual int area() const=0; virtual void show()=0;};class rectangle : public shape{ public: int _with; int _height; rectangle(int with,int height):_with(with),_height(height){} int area()const ...
c++ | 2011-10-12 23:19 | 阅读 1445 次 | 评论 0 条
浏览66690次