上一页 1 ··· 6 7 8 9 10
摘要: 1 /**************************头文件***************************/ 2 3 #ifndef _LINK_H_ 4 #define _LINK_H_ 5 6 #include 7 #include 8 #include 9 10 11 #define Test(arg) if(arg == NULL){\ 12 printf("Invalid arg!\n");\ 13 return -1;\ 14 } 15 16 /*单链表的实现可以各有不同,只要该实现,符... 阅读全文
posted @ 2013-08-02 15:24 夕相待 阅读(577) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 5 6 #define Test(arg) if(arg == NULL){\ 7 printf("Invalid arg!\n");\ 8 return -1;\ 9 } 10 11 /*单链表的实现可以各有不同,只要该实现,符合链表的定义即可。 12 *单链表最重要的数据结构是元素结点, 13 *最重要的操作是插入结点,删除结点和遍历。 14 *其它的操作基本上是这3个操作的组合,依据具体的要求而定。 15 */ 16 17 /***... 阅读全文
posted @ 2013-08-02 12:56 夕相待 阅读(350) 评论(0) 推荐(0) 编辑
摘要: /**********************头文件数据封装及函数声明****************/#ifndef _S_LIST_H#define _S_LIST_H#include #include #define PRINT printf("LINE: %d\n", __LINE__);/*单链表的实现可以各有不同,只要该实现,符合链表的定义即可。 *单链表最重要的数据结构是元素结点, *最重要的操作是插入结点,删除结点和遍历。 *其它的操作基本上是这3个操作的组合,依据具体的要求而定。*//****************************... 阅读全文
posted @ 2013-08-01 20:22 夕相待 阅读(725) 评论(0) 推荐(0) 编辑
摘要: //C++函数模板实例#include template void Swap(Any &a, Any &b);int main(){ using namespace std; double i = 10.123, j = 20.124; Swap(i, j); cout void Swap(Any & a, Any & b){ Any temp; temp = a; a = b; b = temp;} 阅读全文
posted @ 2013-07-22 19:01 夕相待 阅读(430) 评论(0) 推荐(0) 编辑
摘要: 在该示例中我们显式定义了复制构造函数来代替默认复制构造函数, 在该复制构造函数的函数体内, 不是再直接将源对象所申请空间的地址赋值给被初始化的对象, 而是自己独立申请一处内存后再将源对象的属性复制过来, 此时book1对象的 book_name 与book2 对象的 book_name 就是指向两处不同的内存单元, 这样即便是源对象book1 被销毁后被初始化的对象book2也不会再受到影响。#include using namespace std;class book{private:char * book_name;public:book(const char * name){cout . 阅读全文
posted @ 2013-07-21 21:09 夕相待 阅读(354) 评论(0) 推荐(0) 编辑
摘要: //默认复制构造函数的不足//尽管有默认的复制构造函数来解决一般对象与对象之间的初始化问题, 但是在有些情况下我们必须手动显式的去定义复制构造函数, 例如:#include using namespace std;class Book{private:char *book_name;public:Book(const char *name)//构造函数{cout << "构造函数分配内存" << endl;book_name = new char[strlen(name) + 1];strcpy(book_name, name);}//Book(co 阅读全文
posted @ 2013-07-21 20:34 夕相待 阅读(654) 评论(0) 推荐(0) 编辑
摘要: //在C++中应该养成习惯:只用静态成员函数引用静态成员数据,而不引用非静态成员数据#include using namespace std;class st_info //定义学生信息类{ private: string name; int num; float score; static float sum; // 静态数据成员 static int count; // 静态数据成员 public: st_info(string, int, float);//构造函数 void total(); static float average(); };st_info:: st_info(st. 阅读全文
posted @ 2013-07-19 16:59 夕相待 阅读(941) 评论(1) 推荐(0) 编辑
摘要: //为什么类的成员中不能包括动态分配的数据,若包含静态数据怎么使用?#include using namespace std;class point{ private: static int xres; int yres; public: point(int = 0,int = 0); void set_point(int, int) ; void get_point();};point::point(int x, int y){ // xres = x; yres = y;}void point:: set_point(int x, int y){ // xres = x; yres = . 阅读全文
posted @ 2013-07-19 16:02 夕相待 阅读(436) 评论(1) 推荐(0) 编辑
摘要: #include #include using namespace std;struct stud//学生信息结构体{ char name[10]; int num; int (* set_info)(char *, int*);//设置学生信息,一般使用回调函数 void (* print_info)(char *, int);//打印学生信息,一般使用回调函数};int setinfo(char *name, int *num)//此函数结构体中普通变量赋值{ strcpy(name, "zhang_san"); *num = 1001; return 0;}void 阅读全文
posted @ 2013-07-19 15:03 夕相待 阅读(3845) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10