上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 49 下一页
摘要: // 第二十三模板 7复杂类模板/*#include <iostream>using namespace std;const int size=10;class people{public: people(int i):x(i){}; people():x(0){} int GetAge()const{ return x;} void show()const{cout<<x<<endl;}private: int x;};template <class T>class num{public: num(int Tsize=size); //带一个整 阅读全文
posted @ 2012-10-04 19:55 简单--生活 阅读(432) 评论(0) 推荐(0) 编辑
摘要: //第二十三模板 3具体化函数模板//具体化函数模板, 顾名思义, 即具体化了函数参数和功能的模板//1 函数模板不能重载/*#include <iostream>using namespace std;template <class T>void Swap(T &a, T &b);struct people{ char name[10]; int age;};void show(people &p);int main(){ int i=10,j=20; cout<<"初始值i="<<i<< 阅读全文
posted @ 2012-10-04 19:54 简单--生活 阅读(322) 评论(0) 推荐(0) 编辑
摘要: //第二十三模板 1什么是模板/*//未使用模板程序#include <iostream>using namespace std;void swap(int &rx, int &ry){ int temp = rx; rx = ry; ry = temp;}void swap(float &rx, float &ry){ float temp = rx; rx = ry; ry = temp;}void swap(double &rx, double &ry){ double temp = rx; rx = ry; ry = temp 阅读全文
posted @ 2012-10-04 13:36 简单--生活 阅读(143) 评论(0) 推荐(0) 编辑
摘要: //第二十三模板 2重载模板/*#include <iostream>using namespace std;const int num=10;template<class T>void Swap(T&rx, T&ry){ cout<<"执行函数 void Swap(T &rx, T &ry)"<<endl; T temp = rx; ry = rx; rx = temp;}template<class T>void Tswap(T ar1[], T ar2[], int num){ 阅读全文
posted @ 2012-10-04 13:36 简单--生活 阅读(120) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 6未命名的命名空间/*#include <iostream>using namespace std;namespace { int x=2;}namespace { int y=3;}int main(){ cout<<"x:"<<x<<" y:"<<y<<endl; //输出的结果就是未命名空间的x和y的值,其实我们也可以把它们看帮是全局的变量 return 0;}*/// 1 未命名命名空间与全局变量的区别// 2 未命名命名空间与static的区别// 3 未命 阅读全文
posted @ 2012-10-01 23:51 简单--生活 阅读(467) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 4使用关键字using//不地using namespace只有在它声明的作用域中有效,假如超出这个作用域,那么就要重新声明才能够直接使用该空间中的成员/*#include <iostream>using namespace std;namespace num{ int x=10; int y=20;}int main(){ { using namespace num; cout<<"x:"<<x<<" y:"<<y<<endl; } //cout<<&q 阅读全文
posted @ 2012-10-01 23:50 简单--生活 阅读(166) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 5为你的命名空间取个别名/*#include <iostream>using namespace std;namespace people_compay_boss{ int x=9;}namespace pcd = people_compay_boss;int main(){ cout<<pcd::x<<endl; cout<<people_compay_boss::x<<endl; return 0;}*/ 阅读全文
posted @ 2012-10-01 23:50 简单--生活 阅读(186) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 1什么是命名空间//命名宽间主要解决命名冲突的问题,即重名问题/*#include <iostream>using namespace std;int x=1; namespace people{ char name[10] = "Jack";};int main(){ int x=3; cout<<"x:"<<x<<endl; //这个是局部的x变量 cout<<"::x:"<<::x<<endl; //全局的x变量, 前面添加作用域 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(185) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 2创建命名空间//1 扩充命名空间的内容// 同一个命名空间可以在程序中出现多次,也就是说我们可以多次重复创建同一个命名空间//2 尽量在命名空间之外定义函数/*#include <iostream>using namespace std;namespace func{ void swap(int &rx, int &ry); void compare(int x, int y);}int main(){ int x=5, y=6; func::swap(x,y); func::compare(x,y); return 0;}void func::s 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(180) 评论(0) 推荐(0) 编辑
摘要: //第二十二章 3使用命名空间/*#include <iostream>using namespace std;namespace func{ const int cx=20; const int cy=50; class num{ public: num(); ~num(); void size(int a, int b); void swap(int rx, int ry); void compare(int ax, int ay); int returnX(); int returnY(); static int z; private: int x; int y;... 阅读全文
posted @ 2012-10-01 23:49 简单--生活 阅读(161) 评论(0) 推荐(0) 编辑
上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 49 下一页
简单--生活(CSDN)