摘要: 将字符串分成两部分,前半部分按ASCII码升序排序,后半部分不变(如果字符串是奇数个,则中间的字符不变)再将前后两部分交换,最后将该字符串输出。 阅读全文
posted @ 2018-12-23 19:02 super行者 阅读(340) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; char * deleteChar (char * src, char c) { if (src == NULL) return NULL; char * p = src; char * head = src; while (*p != '\0') { if ... 阅读全文
posted @ 2018-12-23 19:01 super行者 阅读(268) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string.h>using namespace std;char * strcat1 (char * dest, char * src){ if ((dest==NULL) || (src==NULL)) return NULL; char 阅读全文
posted @ 2018-12-23 19:00 super行者 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 汉字作为一个字符处理,已知:汉字编码为双字节,其中首字节<0,尾字节在0~63以外(如果一个字节是 -128 ~ 127) 阅读全文
posted @ 2018-12-23 18:59 super行者 阅读(236) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; void calculate (const char * src, int * max0, int * max1) { if (src == NULL) return; int tmpCnt=1; *max0 = 1; *max1 = 1; while (*src++) ... 阅读全文
posted @ 2018-12-23 18:58 super行者 阅读(541) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; char * replace (char * in, char * s1, char * s2, char *out) { if ((in==NULL)||(s1==NULL)||(s2==NULL)||(out==NULL)) return NULL; char *pOut = out; ... 阅读全文
posted @ 2018-12-23 18:57 super行者 阅读(376) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; #define BIT(n) (0x1 T set_bit (T value, T bit_n) { value |= BIT(bit_n); return value; } template T clear_bit (T value, T bit_n) { value &= ~BIT(b... 阅读全文
posted @ 2018-12-23 18:56 super行者 阅读(124) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; #define BIT(n) (0x1=0; i--) { if (c & BIT(i)) cout << "1"; else cout << "0"; } cout <<"b" << endl; } int m... 阅读全文
posted @ 2018-12-23 18:55 super行者 阅读(688) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; bool checkLittleEnd (void) { union test { int a; char b; } t; t.a = 1; return (t.b==1); } int main() { if (checkLittle... 阅读全文
posted @ 2018-12-23 18:53 super行者 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 【自我总结】 1.默认构造函数不仅可以是无参的,也可以是有参的,但所有参数必须指定默认值。一个类只能有一个默认构造函数。 2.什么时候调用默认构造函数? a.声明类的对象时没有括号时。如:classA objA; b.子类构造函数没有显式调用父类构造函数时 3.构造函数中的默认参数要从右向左指定。 阅读全文
posted @ 2018-12-23 18:49 super行者 阅读(3058) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class demo { public: static int i; // 这里不可以初始化非const static变量! static const int j = 1; // 1st place to initiate for const static varia... 阅读全文
posted @ 2018-12-23 18:48 super行者 阅读(462) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class demo { public: static void showObjCount(void); private: static int count; static const int j = 1; public: void funcObj(void); demo(i... 阅读全文
posted @ 2018-12-23 18:47 super行者 阅读(403) 评论(0) 推荐(0) 编辑
摘要: class EMPTY { public: EMPTY(); //默认构造函数 EMPTY(const EMPTY &); //复制构造函数 ~EMPTY();//默认析构函数 EMPTY & operator=(const EMTPY &); //赋值运算符 EMPTY * operator&(); //取址运算符 const EMPTY * ... 阅读全文
posted @ 2018-12-23 18:46 super行者 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 普通构造函数可以被隐式调用,而explicit构造函数(显式构造函数)只能被显式调用 关于隐式转换,参考:【转】这篇文章 首先, C++中的explicit关键字只能用于修饰只有一个参数的类构造函数, 它的作用是表明该构造函数是显示的, 而非隐式的, 跟它相对应的另一个关键字是implicit, 意 阅读全文
posted @ 2018-12-23 18:44 super行者 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 复制构造函数应用场景: 1.一个对象以值传递的方式传入函数体 2.一个对象以值传递方式从函数返回 3.一个对象需要通过另外一个对象进行初始化 阅读全文
posted @ 2018-12-23 18:42 super行者 阅读(408) 评论(0) 推荐(0) 编辑
摘要: 如果复制的对象中引用了某个外部的内容(例如分配在堆上的数据),那么在复制这个对象的时候,让新旧两个对象指向同一个外部的内容,就是浅复制;如果在复制这个对象的时候为新对象制作了外部对象的独立的COPY,就是深复制。 深拷贝和浅拷贝主要是针对类中的指针和动态分配的空间来说的,因为对于指针只是简单的值复制 阅读全文
posted @ 2018-12-23 18:40 super行者 阅读(402) 评论(0) 推荐(0) 编辑
摘要: A & operator= (A & b) {} A obj1; A obj2(1,2); obj1 = obj2; //这条赋值语句可理解如下: obj1.=(obj2) , 相当于obj1调用了它自己的=(A &b) 函数, 而=就是函数名。 因此obj1=obj2这句函数调用本身是有返回值的, 阅读全文
posted @ 2018-12-23 18:36 super行者 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 全部模板特例化 模板中所有参数全被指定为确定的类型 部分模板特例化分两种情况 1.对部分模板参数进行特例化 2.使用具有某一特征的类型,对模板参数进行特例化 混合这两种情况的例子如下 总结: template后<>的列表中要列出没有明确指明类型的 typename 下面是一段示例代码: 下面是另一段 阅读全文
posted @ 2018-12-23 17:17 super行者 阅读(439) 评论(0) 推荐(0) 编辑
摘要: 下面代码展示通过继承方式把模板中与参数无关的代码分离出来 阅读全文
posted @ 2018-12-23 10:44 super行者 阅读(187) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; class Shape { public: virtual void display(void) = 0; virtual void setValue(void) = 0; }; class Circle: public Shape { public: Circle(int x=1):radius(x){... 阅读全文
posted @ 2018-12-20 22:02 super行者 阅读(490) 评论(0) 推荐(0) 编辑
摘要: 代码中Author和Singer以virtual方式继承Person,解决了Author_Singer实例拥有两份Person copy的问题,这是一种解决方法。 另一种方法是明确指定引用的子类:pp.Author::eat(); 下面代码显示了,使用和不使用virtual来继承基类时,各个类的构造 阅读全文
posted @ 2018-12-19 21:40 super行者 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 1.如何在预处理阶段计算sizeof? 阅读全文
posted @ 2018-12-18 06:29 super行者 阅读(72) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class Person { public: virtual void print(void) { cout << "I am a Person!" << endl; } }; class Chinese: public Person { public: virt... 阅读全文
posted @ 2018-12-18 05:26 super行者 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 下面代码显示了不同调用虚函数时的实际执行情况: 执行结果为: 阅读全文
posted @ 2018-12-18 05:17 super行者 阅读(152) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class String { public: String(const char * x=NULL); String(const String & x); ~String(); String & operator= (const String & x); Stri... 阅读全文
posted @ 2018-12-15 13:43 super行者 阅读(595) 评论(0) 推荐(0) 编辑
摘要: 下面代码侧面说明,编译器在构造函数末尾处初始化vptr。所以如果在构造函数中调用virtual函数,动态绑定不会起作用,只会调用本类中的virtual函数: 下面代码是我自己写的读取虚函数表示例: 屏幕输出: 如果将 改为 class Base{ public: virtual void func0 阅读全文
posted @ 2018-12-13 20:45 super行者 阅读(190) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class MyString { public: MyString(const char * s=NULL) { if (s == NULL) { m_string = new char[1]; m_string[... 阅读全文
posted @ 2018-12-13 06:24 super行者 阅读(542) 评论(0) 推荐(0) 编辑
摘要: [转自]https://blog.csdn.net/geophyboy/article/details/14119775 问题(知识点)描述:a. 在C++的类的成员函数中,允许直接访问该类的对象的私有成员变量。b. 在类的成员函数中可以访问同类型实例的私有变量。c. 拷贝构造函数里,可以直接访问另 阅读全文
posted @ 2018-12-13 05:40 super行者 阅读(1393) 评论(0) 推荐(0) 编辑
摘要: [转自] https://blog.csdn.net/ipmux/article/details/45038869 Overload、Override和Overwrite英文接近,比较容易混淆,再加上翻译五花八门,使用时张冠李戴,往往是今天清楚明天糊涂。这三个概念在前面章节已分别讨论,这里再集中比较 阅读全文
posted @ 2018-12-12 21:10 super行者 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 同一个作用域内,可以声明几个功能类似的同名函数,但是这些同名函数的形式参数(指参数的个数、类型或者顺序)必须不同。您不能仅通过返回类型的不同来重载函数。 阅读全文
posted @ 2018-12-12 20:35 super行者 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 引用:https://www.cnblogs.com/burellow/archive/2011/05/25/2056506.html 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数。这是虚函数的基本功能,就不再解释了。 2) 构造函数 阅读全文
posted @ 2018-12-11 22:34 super行者 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 只有虚函数才使用动态绑定,其它全部是静态绑定 编译阶段决定:non-virtual 函数->静态绑定->绑定静态类型 运行时决定: virtual 函数->动态绑定->绑定动态类型 虚函数是动态绑定的,但是为了执行效率,缺省参数是静态绑定的。永远记住: “绝不重新定义继承而来的缺省参数(Never 阅读全文
posted @ 2018-12-11 22:04 super行者 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 1.在C++中,只要不明确指定是public,默认是private 2.virtual关键字主要是实现动态绑定。要触发动态绑定,必须满足两个条件: 第一,指定为虚函数; 第二,通过基类类型的引用或指针调用。 只要基函数定义了virtual,继承类的该函数也就具有virtual属性 纯虚函数为后代类提 阅读全文
posted @ 2018-12-10 21:20 super行者 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 上面main()函数执行后的输出为: Normal Contructor: 1 Normal Contructor: 2 end of program Destructor: 2 Destructor: 1 阅读全文
posted @ 2018-12-10 21:00 super行者 阅读(287) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; class String { public: String(const char * str=NULL) { if (str == NULL) { //这两行代码保证了: //任一String对象的m_string都不... 阅读全文
posted @ 2018-12-09 22:16 super行者 阅读(245) 评论(0) 推荐(0) 编辑