cpp积累
来源:互联网 发布:java猎魔人下载 编辑:程序博客网 时间:2024/06/13 00:35
@font-face{font-family:"Times New Roman";}@font-face{font-family:"宋体";}@font-face{font-family:"Symbol";}@font-face{font-family:"Arial";}@font-face{font-family:"黑体";}@font-face{font-family:"Courier New";}@font-face{font-family:"Wingdings";}@font-face{font-family:"新宋体";}@font-face{font-family:"Courier New CYR";}p.0{margin:0pt;margin-bottom:0.0001pt;layout-grid-mode:char; text-align:justify;font-size:10.5000pt; font-family:'Times New Roman'; }div.Section0{margin-top:72.0000pt;margin-bottom:72.0000pt;margin-left:90.0000pt;margin-right:90.0000pt;size:612.0000pt 792.0000pt;}namespace sun
{
template<class T1, class T2>
struct pair
{
// member
T1 first;
T2 second;
pair() : first(T1()), second(T2()) // ???T1,T2后需加(),不然会出错,为什么???
{ } // T1,是类类型,而firsrt 初始化需要一个对象
// T1() 创建了一个无名对象
pair(const T1& a, const T2& b)
: first(a) , second(b)
{ }
};
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// kind of
@font-face{font-family:"Times New Roman";}@font-face{font-family:"宋体";}@font-face{font-family:"Symbol";}@font-face{font-family:"Arial";}@font-face{font-family:"黑体";}@font-face{font-family:"Courier New";}@font-face{font-family:"Wingdings";}@font-face{font-family:"新宋体";}@font-face{font-family:"Courier New CYR";}p.0{margin:0pt;margin-bottom:0.0001pt;layout-grid-mode:char; text-align:justify;font-size:10.5000pt; font-family:'Times New Roman'; }div.Section0{margin-top:72.0000pt;margin-bottom:72.0000pt;margin-left:90.0000pt;margin-right:90.0000pt;size:612.0000pt 792.0000pt;}
#include <iostream>
#include <vector>
using namespace std;
class Shape
{
public:
virtual void print()
{ cout << "Shape" << endl; }
};
class Circle : public Shape
{
public:
void print()
{ cout << "Circle" << endl; }
};
class Triangle : public Shape
{
public:
void print()
{ cout << "Triangle" << endl; }
};
void kindOfShape( const vector<class Shape * > & con);
int main()
{
vector<class Shape * > con;
con.push_back( new Circle );
con.push_back( new Triangle );
kindOfShape( con );
return 0;
}
void kindOfShape( const vector<class Shape * > & con)
{
cout << "0 or 1" << endl;
int i = 0;
cin >> i;
con[i]->print();
}
//////////////
0 ---------> Circle
1 ----------> Triangle
///////////////////////////////////////////
@font-face{font-family:"Times New Roman";}@font-face{font-family:"宋体";}@font-face{font-family:"Symbol";}@font-face{font-family:"Arial";}@font-face{font-family:"黑体";}@font-face{font-family:"Courier New";}@font-face{font-family:"Wingdings";}@font-face{font-family:"新宋体";}@font-face{font-family:"Courier New CYR";}p.0{margin:0pt;margin-bottom:0.0001pt;layout-grid-mode:char; text-align:justify;font-size:10.5000pt; font-family:'Times New Roman'; }div.Section0{margin-top:72.0000pt;margin-bottom:72.0000pt;margin-left:90.0000pt;margin-right:90.0000pt;size:612.0000pt 792.0000pt;}
在类中定义const常量
#include <iostream>
#include <vector>
using namespace std;
class Shape
{
enum{MAX = 20};
public:
virtual void print()
{ cout << "Shape" << endl; }
private:
//const int i;
const static int j;
int arr[MAX];
};
//const int Shape::i = 9; // “const int Shape::i”: 不允许成员函数重新声明
//int Shape::j = 99; // 重定义;不同的类型修饰符
const int Shape::j = 99;
int main()
{
return 0;
}
- cpp积累
- C/CPP点滴积累—#define ,typedef
- C/CPP点滴积累—程序内存
- C/CPP点滴积累--void小记
- C/CPP点滴积累—数组数据类型
- 工作积累之NDK编译多个cpp
- C/CPP点滴积累—scanf,getchar之输入缓冲区
- C/CPP点滴积累--C、CPP函数定义的小差别
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- C/CPP点滴积累—数组做函数参数退化为指针
- C/CPP点滴积累—数组名作为常量的错误典型
- C/CPP点滴积累—数据类型--结构体、联合体、枚举类型
- gridview的事件
- 20个电脑小技巧
- Oracle数据库出现的奇怪表名及其清除方法
- rapidshare
- 电脑操作实用技巧60招
- cpp积累
- 顺序栈(C#)
- 链式队列(数据结构C#)
- 【转帖】把自己的事情管好就是中国对人类的最大贡献
- DirectX Sample : EmptyProject 框架认识
- 做人低调是种智慧
- SQLite数据库是中小站点CMS的最佳选择
- FileUpload的文件上传
- 专访 Amoeba 项目开发者陈思儒