摘要: // leran.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include#include #include#includeusing namespace std;class GT_cls{public:GT_cls(size_t val = 0):bound(val){}bool operator()(const string &s){return s.size()>=bound;}private:std::string::size_type bound;};int _tmain(int argc, _TCHAR* ar 阅读全文
posted @ 2013-10-09 13:10 CrazyCode. 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 在函数形参表后面写上 =0 以指定纯虚函数:class Disc_item:public Item_base{public: double net_price(std::size_t) const = 0;}将函数定义为纯虚能够说明,该函数为后代类型提供了可以覆盖的接口。但是这个类中的版本绝不会调用。重要的是,用户将不能穿件Disc_item类型的对象。试图创建抽象基类的对象将发生编译时错误.Disc_item discounted;//error:can't define a Disc_item object;Bulk_item bulk;//Bulk_item继承自Disc_ite 阅读全文
posted @ 2013-10-09 13:09 CrazyCode. 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 派生类构造函数 派生类的构造函数受继承关系的影响,每个派生类构造函数除了初始化自己的数据成员之外,还要初始化基类,也会运行基类的构造函数 。#include "stdafx.h"#include using namespace std;class Ctest{public:Ctest(int a=1,int b=2,int c=3){cout discount_policy();itemP -> discount_policy();//错误...因为在Item_base里面没有这个方法discount_policy();设计派生类的时候,只要可能,最好避免与基类成员的 阅读全文
posted @ 2013-10-09 13:07 CrazyCode. 阅读(233) 评论(0) 推荐(0) 编辑