上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页
摘要: class Test{private: char *ptr;pubic:};若Test test1 ("Hello");则调用的是构造函数若Test test2(test1;则调用的是拷贝构造函数若Test test2 = test1;则调用的是拷贝构造函数若Test test2; test2 = test1;则调用的是拷贝构造函数若Test test2 = "hello";则先调用的是构造函数生成临时对象,然后再调用拷贝构造函数初始化编译器总的原则是保证运算符两边的类型的一致性。 阅读全文
posted @ 2012-12-30 10:17 l851654152 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1.构造函数构造函数必须和类名相同,所以要有多个构造函数必须使用重载。若没有显式的定义一个构造函数,则系统会默认生成一个默认构造函数。构造函数的作用是初始化对象,在对象被建立的时候会自动调用构造函数来对对象进行初始化。构造函数实际上是对成员变量赋值,只是第一个被调用的函数,所以习惯称之为构造函数。真正的初始化是,初始化列表,这个在构造函数之前调用,可以通过这种方式传参调用基类的构造函数。关键字inline,const,explicit,virtual,operator,priavte,protected,public运算符new,delete,typeid,dynamic_cast<&g 阅读全文
posted @ 2012-11-14 23:42 l851654152 阅读(151) 评论(0) 推荐(0) 编辑
摘要: inline 相对函数调用执行效率更高。如果一种语言只有类而没有多态,只能叫基于对象的而非面向对象的。 阅读全文
posted @ 2012-10-27 20:58 l851654152 阅读(136) 评论(0) 推荐(0) 编辑
摘要: i=(i&0x55555555)<<1|(i>>>1)&0x55555555;//交换相邻的两个位 i=(i&0x33333333)<<2|(i>>>2)&0x33333333;//交换相邻的两个两位 i=(i&0x0f0f0f0f)<<4|(i>>>4)&0x0f0f0f0f;//交换相邻的两个四位 i=(i&0x00ff00ff)<<8|(i>>>8)&0x00ff00ff;//交换相邻的两个八位 i=(i& 阅读全文
posted @ 2012-09-25 23:30 l851654152 阅读(290) 评论(0) 推荐(0) 编辑
摘要: 字符串赋值给一个指针,则这个指针指向字符串串常量,例:char *p = "abdcd".。 赋值给一个对象或者通过拷贝函数则必须要有指针所指向的内存。strcpy(dest,"abcde");这里的dest需要有指向的内存。 阅读全文
posted @ 2012-09-12 09:03 l851654152 阅读(163) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #define OK 1 3 int BubbleSort(int *a,int length); 4 int main() 5 { 6 int a[9] = {5,8,7,36,54,21,2,3,19}; 7 BubbleSort(a,9); 8 for(int i = 0;i < 9;i++) 9 {10 printf("%d ",a[i]);11 }12 printf("\n");13 return 0;14 }15 16 int BubbleSo... 阅读全文
posted @ 2012-09-08 14:35 l851654152 阅读(150) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #define OK 1 3 int SelectSort(int *a,int length); 4 int main() 5 { 6 int a[8] = {5,7,52,87,64,61,2,38}; 7 SelectSort(a,8); 8 for(int i = 0;i < 8;i++) 9 {10 printf("%d ",a[i]);11 }12 printf("\n");13 return 0;14 }15 16 int SelectSor... 阅读全文
posted @ 2012-09-08 13:33 l851654152 阅读(158) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 typedef struct Lode{ 5 int elem; 6 struct Lode *pnext; 7 }LNODE, *List; 8 9 /**10 **创建一个链表11 **/12 void CreateList(List &L,int n)13 {14 L = (struct Lode*)malloc(sizeof(List));15 L->pnext = NULL;16 17 int num;18 f... 阅读全文
posted @ 2012-09-07 21:28 l851654152 阅读(185) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 void InsertSort(int *a,int length); 3 int main() 4 { 5 int a[8] = {5,8,7,10,25,64,3,1}; 6 InsertSort(a,8); 7 for(int i = 0;i<8;++i) 8 { 9 printf("%d ",a[i]);10 }11 printf("\n");12 return 0;13 }14 void InsertSort(int *a,int length)... 阅读全文
posted @ 2012-09-07 11:05 l851654152 阅读(166) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdlib.h> 2 #include <string.h> 3 #include <stdio.h> 4 void Reverse(char *pbegin,char *pend) 5 { 6 char temp; 7 while(pbegin < pend) 8 { 9 temp = *pbegin;10 *pbegin = *pend;11 *pend = temp;12 pbegin++;13 pend--;14 }15 }16... 阅读全文
posted @ 2012-09-06 23:24 l851654152 阅读(148) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页