摘要: //13.2 抽像类与体类(Abstract & Concrete Classes)//只要子类中尚有未被覆盖定义的纯虚函数,那么,子类相对于抽像基类的抽像状态不变//该类继承结构由下列程序代码实现之:#include <iostream>class Display{public: virtual void inint()=0; virtual void write(char* pStr)=0;};//定义两个纯虚函数class Monochrome : public Display{ virtual void inint(); //覆盖 virtual void writ 阅读全文
posted @ 2012-02-12 22:28 简单--生活 阅读(553) 评论(0) 推荐(0) 编辑
摘要: #ifndef HEADER_ACCOUNT#define HEADER_ACCOUNT#include<string>using std::string;class Account{ string acntNumber; double balance;public: //构造函数 Account(string _acntNumber, double _balance=0.0); //定义一个虚函数display并定义为const型 virtual void display()const; //定义返回double类型函数getBalance double getBala... 阅读全文
posted @ 2012-02-12 21:50 简单--生活 阅读(339) 评论(0) 推荐(0) 编辑
摘要: //A: 操作符重载实现为类成员函数/*#include <iostream>class Person{private: int age;public: Person(int a){ this->age=a; } //inline bool operator==(const Person &ps)const; inline bool operator==(const Person *ps)const;};//inline bool Person::operator==(const Person &ps)const{// std::cout<<&qu 阅读全文
posted @ 2012-02-12 18:19 简单--生活 阅读(998) 评论(0) 推荐(0) 编辑
摘要: http://blog.sina.com.cn/s/blog_4b3c1f950100kker.htmloperator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名。这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算符的使用方法与其原来一致,另一方面扩展其功能只能通过函数的方式(c++中,“功能”都是由函数实现的)。一、为什么使用操作符重载?对于系统的所有操作符,一般情况下,只支持基本数据类型和标准库中提供的class,对于用户自己定义的class,如果想支持基本操作,比如比较大小,判断是否相等,等等,则需要 阅读全文
posted @ 2012-02-12 18:18 简单--生活 阅读(139295) 评论(8) 推荐(11) 编辑
摘要: //以下对上面的程序进行改进#include <iostream>using namespace std;class A{public: virtual void fn()=0; //如果这个声明后不定义的话,必须得声明为纯虚函数才行,不然不能通过编译}; //A类我中无fn成成员函数class B : public A{ public: void fn(){ cout<<" I am Class B"; };};class C : public A{ public: void fn(){ cout<<" I am Class 阅读全文
posted @ 2012-02-12 16:22 简单--生活 阅读(331) 评论(0) 推荐(0) 编辑
简单--生活(CSDN)