上一页 1 ··· 5 6 7 8 9 10 11 下一页
摘要: copy构造函数被用来"以同型对象初始化醉卧对象",copy assignment操作符被用来"从另一个同型对象中拷贝其值到自我对象":#include "stdafx.h"#include using namespace std;class Widget{public:Widget();//默认构造函数Widget(const Widget& rhs);//复制构造函数Widget& operator = (const Widget& rhs);//赋值操作符};int _tmain(int argc, _T 阅读全文
posted @ 2013-10-12 16:10 CrazyCode. 阅读(405) 评论(0) 推荐(0) 编辑
摘要: size_t只是一个typedef,是c++计算个数,如字符串内的字符个数或者stl容器内的元素个数时用的某种不带正负号unsigned类型。它也是vector,deque和string内的operator[]函数接受的参数类型。 阅读全文
posted @ 2013-10-12 15:52 CrazyCode. 阅读(128) 评论(0) 推荐(0) 编辑
摘要: c++中,模板是泛型编程的基础.模板是创建类或函数的蓝图或公式。函数模板是一个独立于类型的函数,可作为一种方式,产生函数的特定类型版本。模板定义以关键字template开始,后接模板形参表,模板形参表是用尖括号括住的1个或多个模板形参的列表,形参之间以逗号分隔.#include "stdafx.h"#include #includeusing namespace std;template int compare(const T &v1,const T &v2){if(v1inlineT min(const T&,const T&);模板类型形 阅读全文
posted @ 2013-10-11 01:05 CrazyCode. 阅读(263) 评论(0) 推荐(0) 编辑
摘要: // 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) 编辑
摘要: protected成员可以认为protected访问标号是private 和public 的混合:1.像private成员一样,protected成员不能被类的用户访问.2.像public成员一样,protected成员可被该类的派生类访问.此外,protected还有另一个重要性质:派生类只能通过派生类对象访问其基类的protected成员,派生类对其基类类型对象的protected成员没有特殊访问权限.少量的理解:#include "stdafx.h"#includeusing namespace std;class Ctest{public:Ctest(int a=1 阅读全文
posted @ 2013-10-07 10:08 CrazyCode. 阅读(538) 评论(0) 推荐(0) 编辑
摘要: 最大子数组问题:找出数组中和最大的最大的非空连续子数组.这里定义一个ret的类来进行存储三个值.用public只是用来方便读取和使用..#include "stdafx.h"#includeusing namespace std;class ret{public:ret(void){};ret(in... 阅读全文
posted @ 2013-10-07 02:29 CrazyCode. 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 分治法的思想:将原问题分解为几个规模较小但类似于原问题的子问题,递归地求解这些子问题,然后再合并这些子问题的解来建立原问题的解。 1 2 #include "stdafx.h" 3 #include 4 using namespace std; 5 6 void Merge(int *arr,int p ,int q ,int r);//归并排序 7 8 void mergesort(int *arr,int p,int r); 9 void ViewData(int *,int len);10 int _tmain(int argc, _TCHAR* argv[])11 阅读全文
posted @ 2013-10-06 00:54 CrazyCode. 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 插入排序:对于少量元素的排序,是一个比较有效的算法。#include "stdafx.h"#includeusing namespace std;void Insertion_Sort(int *,int );//插入升序排序void Insertion_SortDown(int *,int );//插入降序排序void ViewData(int *,int len);//读数据int _tmain(int argc, _TCHAR* argv[]){int arr[]={5,2,12,34,2,4,6,1,3};size_t len=sizeof(arr)/sizeof( 阅读全文
posted @ 2013-10-06 00:49 CrazyCode. 阅读(144) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 下一页