- 博客(15)
- 资源 (8)
- 收藏
- 关注
原创 动态类型识别 : 利用多种方法进行动态类型识别
//动态类型识别 : 利用多态进行动态识别 #include using namespace std; class Parent { public: enum{ ID = 0 }; virtual int type() { return ID; } }; class Child : public Parent { public: enum{ ID = 1 }; int t
2015-12-30 22:30:36 821 1
原创 在构造函数中抛出异常的结果
//异常处理 #include using namespace std; class Test { private: int* p; public: Test() { cout << "Test() "<< endl; p = new int[5]; throw 2; } ~Test() //在构造函数中抛出异常,因对象不完整,造成析
2015-12-30 15:27:21 524
原创 C++中异常处理
//异常处理 #include using namespace std; int Test(int i) { if(i == 1) { throw 0; } else if(i == 2) { throw 'a'; } else if(i == 3) { throw "Hello"; } else if(i == 4) { throw 0.5;
2015-12-30 10:51:08 297
转载 如何判定一个变量是指针还是非指针
//如何判定一个变量是指针还是非指针 #include using namespace std; template void isPtr(T*) { cout << "void isPtr(T*)" << endl; } void isPtr(...) { cout << "void isPtr(...)" << endl; } int main() { int i = 0; c
2015-12-29 11:02:36 833
原创 STL 中 算法的遍历和排序
//STL 中 算法的遍历和排序 #include #include #include using namespace std; void Show(int & value) //自定义的显示函数 { cout << value << endl; } int Compare(const int& a ,const int& b) /
2015-12-28 21:32:51 367
原创 STL 中 链表(双向链表)和迭代器(iterator)的使用
//STL 中 链表(双向链表)和迭代器的使用 ,,迭代器就理解成指向元素的指针 #include #include using namespace std; void ListUsage() { list l; for(int i=0;i<5;i++) { l.push_back(i+1); //压入元素 } cout << "Elements in l
2015-12-28 20:55:17 1481
原创 STL----stack 和queue的使用
//STL 中 栈和队列的使用 #include #include #include using namespace std; void StackUsage() { stack s; for(int i=0;i<5;i++) { s.push(i+1); //压栈操作 } cout << "Elements in stack is :" << e
2015-12-28 20:23:52 302
原创 STL----vector
//STL 中 向量的使用 (理解成数组类比较好理解,是用模板类实现的) #include #include using namespace std; int main() { vector array(10); cout << "Elements in array is : " << endl; for(int i=0;i<array.size();i++) {
2015-12-28 19:59:30 389
原创 类模版的使用----智能指针
// SmartPointer.h #ifndef _SMARTPOINTER_H_ #define _SMARTPOINTER_H_ template class SmartPointer { private: public: SmartPointer(); SmartPointer(T* pointer); ~SmartPointer(); T& operator
2015-12-28 15:58:00 271
原创 非类型模版参数
#include #include #include using namespace std; template void fn() { T array[N] = {0}; for(int i=0;i<N;i++) { array[i] = i+1; cout << array[i] << " "; } cout << endl; } int main() {
2015-12-28 11:02:46 395
原创 类模版的特化 及 特化的继承
#include #include #include using namespace std; template class Test { private: public: T test(T v) { cout return v; } protected: }; //类模版的特化 template class
2015-12-27 22:19:02 1757
原创 类模版的工程应用
类模版的工程应用 #include #include #include using namespace std; template class A { private: public: T Add(T a,T b); T Minus(T a,T b); protected: }; template T A::Add(T a,T b) { r
2015-12-27 20:16:12 348
原创 函数模版遇上函数重载会发生什么呢?
当函数模版遇上函数重载会发生什么呢? 函数模版可以像普通函数一样被重载 C++编译器优先考虑普通函数; 如果函数模版可以产生一个更好的匹配,那么选择模版; 可以通过空模版实参列表的语法限定编译器只通过模版匹配。 #include #include #include using namespace std; int Max(int a,int b) { cout << "int
2015-12-26 16:40:04 317
原创 C++ ----模版
#include #include #include using namespace std; template void Swap(T& a,T& b) { T t = a; a = b; b = t; } int main() { int a = 1; int b = 2; cout << "---------------自动类型推倒调用---------------
2015-12-26 15:09:50 269
原创 指针常量与常量指针
DEV-C编辑器结果: printf("---------------------------------\n"); const int* ip = &a; //常量指针,,地址可变 //*ip = b; //[Error] assignment of read-only location '*ip' ip = &b; printf("------------
2015-12-23 14:49:09 289
the java programming language fourth editionArnoldGoslingHolmes06
2014-08-30
ascii-码表
2014-08-30
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人