
c++
文章平均质量分 60
CodeHeng
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
c++超基础:继承概念
一、继承要点原创 2015-01-07 22:05:25 · 390 阅读 · 0 评论 -
delete和delete[]的区别
一直对C++中的delete和delete[]的区别不甚了解,今天遇到了,上网查了一下,得出了结论。做个备份,以免丢失。 C++告诉我们在回收用 new 分配的单个对象的内存空间的时候用 delete,回收用 new[] 分配的一组对象的内存空间的时候用 delete[]。 关于 new[] 和 delete[],其中又分为两种情况:(1) 为基本数据类型分配和回收空间;(2)转载 2015-03-14 15:31:39 · 348 阅读 · 0 评论 -
C++智能指针
#ifndef _SMART_POINTER_H_ #define _SMART_POINTER_H_ template class SmartPointer { public: SmartPointer(); SmartPointer(const T *pointer); ~SmartPointer(); T *operator->(); T &operator*(); bool原创 2015-03-14 15:48:17 · 506 阅读 · 0 评论 -
用 const 限定类的成员函数
类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态数据成员)作任何改变。 在设计类的时候,一个原则就是对于不改变数据成员的成员函数都要在后面加 const,而对于改变数据成员的成员函数不能加 const。所以 const 关键字对成员函数的行为作了更加明确的限定:有 const 修饰的成员函数(指 const 放在函数参数表的后面,而不是在函数前面或者参转载 2015-04-04 10:24:41 · 464 阅读 · 0 评论 -
C++简单内存池的实现
#ifndef _MEM_POOL_H #define _MEM_POOL_H #include #include #include #include #include using std::cout; using std::endl; #define ASSERT(expr) \ do\ {\ if (!(expr))\ {\ fprintf(std原创 2015-04-04 10:30:04 · 719 阅读 · 0 评论 -
inline函数的声明与定义
(一)inline函数(摘自C++ Primer的第三版) 在函数声明或定义中函数返回类型前加上关键字inline即把min()指定为内联。 inline int min(int first, int secend) {/****/}; inline 函数对编译器而言必须是可见的,以便它能够在调用点内展开该函数。与非inline函数不同的是,inline函数必须在调用转载 2015-04-04 10:26:32 · 7125 阅读 · 0 评论 -
字符串转整形
#include #include #include #include #include // return: 0 error int Str2Int(const char* _pInput) { if (NULL == _pInput || strlen(_pInput) > 11 || _pInput[0] == '0') // max length 11 (include原创 2015-09-28 15:05:36 · 651 阅读 · 0 评论 -
从内存中正/反向查找特定字符串,字符串替换的2种方法
#include #include #include #include #include // return: NULL Not Found char* s_strstr(const char* _pBegin, int _MaxLen,const char* _szKey) { if (NULL == _pBegin || NULL == _szKey || _MaxLen原创 2015-09-29 14:21:09 · 2478 阅读 · 0 评论 -
一些编程面试题
#include #include #include #include #define ArraySize(a) (sizeof(a)/sizeof(a[0])) // 斐波那契数列(递归效率低,重复计算多) long long Fibonacci(unsigned int n) { if (0 >= n) { return 0; } el原创 2015-10-09 15:35:40 · 280 阅读 · 0 评论 -
单例模式,完全版
#include #include #include #include class CSingleton { public: static CSingleton* CreateInstance(); // 获取实例 virtual ~CSingleton(); // 对应手动delete后能重新创建实例 void print(); protected:原创 2015-09-23 17:32:15 · 446 阅读 · 0 评论 -
vector、list、deque和map的区别
1 vector 向量 相当于一个数组 在内存中分配一块连续的内存空间进行存储。支持不指定vector大小的存储。STL内部实现时,首先分配一个非常大的内存空间预备进行存储,即capacituy()函数返回的大小,当超过此分配的空间时再整体重新放分配一块内存存储,这给人以vector可以不指定vector即一个连续内存的大小的感觉。通常此默认的内存分配能完成大部分情况下的存转载 2015-10-13 09:05:59 · 621 阅读 · 0 评论 -
C/C++语言编码规范
目录录录 C/C++语言编码规范 1 目录 2 1. 命名规则 4 1.1. 起个合适的名字 4 1.1.1. 类的名称(适用于C++) 4 1.1.2. 方法和函数的名称(适用于C/C++) 4 1.1.3. 含有度量单位的名称(适用于C/C++) 4 1.1.4.转载 2015-10-28 09:43:13 · 649 阅读 · 0 评论 -
c++超基础:操作符重载下(重载符号:=、[]、==、!=)示例
#include using namespace std; /**************************************************************************** 当类中有指针变量时候,需要重载赋值操作符,因为编译器的赋值操作只是简单的值赋值, 会导致对象消亡时调用析构函数释放2次同一片内存,而另外的对象的内存没有释放,造成内存泄漏 *原创 2015-01-05 22:18:13 · 1646 阅读 · 0 评论 -
c++超基础:类的基本操作
/*test.cpp*/ #include #include #include #include using namespace std; class Student { private: int x, y; char *name; public: Student(int a, int b, char *str); ~Student(); void display(void)原创 2014-12-26 23:45:41 · 639 阅读 · 0 评论 -
c++超基础:操作符重载、友员函数
#include using namespace std; class Complex { private: int a; int b; public: Complex(){} ~Complex(){} Complex(int a, int b); friend Complex operator+(const Complex &c1, const Complex &c2); f原创 2015-01-04 22:00:46 · 645 阅读 · 0 评论 -
c++超基础:继承的构造与析构(赋值兼容性原则)
一、概念 二、代码示例 #include using namespace std; class Parent { protected: const char *Name; public: Parent() { Name = "Parent"; } void print() { cout<<"Name: "<<Name<<endl; } };原创 2015-01-07 22:35:37 · 443 阅读 · 0 评论 -
c++超基础:多态——上、虚函数
一、多态的概念 多态:同样的调用行为,表现出不同的表现形态 二、江湖恩怨 不加virtual 关键字和加上virtual 关键字的区别 #include using namespace std; class Boss { private: static Boss *Instance; Boss(){}; public: static Boss* GetInstance(原创 2015-01-08 23:04:27 · 367 阅读 · 0 评论 -
C++超基础:异常处理——上
一、异常处理 1、throw语句将异常抛出,如果当前函数没有try...catch语句能够处理,那么当前函数将立即返回 2、异常被传递到上层调用函数,仍然需要try...catch语句的处理,如果上层函数也没有能力处理该异常,则异常继续向更上层的函数传递,如此循环 3、如果在函数调用栈里面所有函数都没有能力处理该异常,则程序异常终止 4、同一个try语句可以跟上多个catch语句块,同一个原创 2015-01-11 09:42:21 · 594 阅读 · 0 评论 -
STL map的使用
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有转载 2015-01-29 15:31:54 · 537 阅读 · 0 评论 -
c++超基础:多态——下、抽象类与虚函数
一、课堂要点 二、使用示例 #include using namespace std; class Shape { public: virtual double area() = 0; }; class Rectangle : public Shape { double a; double b; public: Rectangle(double原创 2015-01-09 23:31:53 · 389 阅读 · 0 评论 -
C++超基础:类模板——下、类模版的特化
一、类的特化 1、编译器会自动优先选择特化的类模版 2、函数模版和类模版的模版参数也可以是普通数值 #include using namespace std; template class Test { public: void add(T1 a, T2 b) { cout<<"Test"<<endl; cout<<(a + b)<<endl; } }; /* templ原创 2015-01-10 17:31:41 · 670 阅读 · 0 评论 -
C++超基础:STL
一、线性表vector /*test.cpp*/ #include #include using namespace std; int main() { vector array(10); cout<<"array sizez: "<<array.size()<<endl; for (int i=0; i<5; i++) { array[i] = i + 1;原创 2015-01-10 20:48:37 · 420 阅读 · 0 评论 -
c++超基础:函数模版
一、泛指编程 template 告诉编译器使用函数模版,T表示泛指的类型,废话不多说,直接实践 二、示例 #include #include using namespace std; #define GetArrayLen(array, len) (len = sizeof(array)/sizeof(array[0])) template void Swap(T原创 2015-01-10 11:24:03 · 360 阅读 · 0 评论 -
C++超基础:类模版——上
一、类模版 1、类模版与普通函数的实现方式一样 2、类模版在定义对象的时候必须指定类型,否则编译器不会自动推导 二、示例 #include using namespace std; template class Operator { public: T Add(T a, T b) { return a + b; } T Minus(T a, T b)原创 2015-01-10 13:26:08 · 602 阅读 · 0 评论 -
STL常用容器成员函数列表
一、string string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造函数和复制构造函数,如string s1;string s2="hello";都是正确的写法。当构造的string太长而无法表达时会抛出length_error异常原创 2015-02-04 21:10:45 · 1855 阅读 · 0 评论 -
tinyXML的基本使用
一) tinyxml是开源的解析xml库,在遵循开源协议下可以查看和修改源代码,其基本的结构如下 1)TiXmlVisitor:是解析xml重要的访问器,负责遍历所有的xml节点,用户一般不会使用; 2)TiXmlBase:是所有的tinyXml中的类的父类,除了可以建立文档,还有输出文档的结构等接口; 3)T转载 2015-02-05 13:54:29 · 1020 阅读 · 0 评论 -
c++智能指针
//SmartPointer.h #ifndef _SMART_POINTER_H_ #define _SMART_POINTER_H_ template class SmartPointer { public: SmartPointer(); SmartPointer(const T* pointer); ~SmartPointer(); T* operato原创 2015-10-14 15:59:06 · 420 阅读 · 0 评论