随笔分类 - C++ /C
摘要:template class auto_ptr { public: explicit auto_ptr(T *p = 0); // Item M5 有“explicitfor”// 的描述 template // 拷贝构造函数成员模板 auto_ptr(auto_ptr& rhs); // (见Item M28): // 用另一个类型兼容的 // auto_ptr对象 // 初始化一个新的auto_ptr对象 ~auto_ptr(); template // 赋值操作成员模板 auto_ptr& // (见Item M28): operat...
阅读全文
摘要:转自:http://blog.csdn.net/wangtengqiang/article/details/80618061.static用法static 的成员函数和成员变量,可直接通过类名::函数名或类名::变量名直接访问,该函数名和变量名仅跟类相关联在函数名里定义的static变量,改变它的存储结构,多次调用该函数时,该变量仅被初始化一次全局变量与static的静态变量。改变它的作用域,全局变量的范围是整个程序,而static的静态变量的范围仅有该模块1.1 .h 头文件和.cpp头文件的区别2.多态的机制编绎器会为继承体系上的每一个类创建一个虚函数表,表中的每一次指向虚函数的地址。每个
阅读全文
摘要:转自:C++ how to program// String class definition with operator overloading.#ifndef STRING_H#define STRING_H#include using std::ostream;using std::istream;class String{ friend ostream &operator>( istream &, String & );public: String( const char * = "" ); // conversion/default
阅读全文
摘要:16.5Write a program to find whether a machine is big endian or little endianBig-Endian和Little-Endian的定义如下:1) Little-Endian就是低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。2) Big-Endian就是高位字节排放在内存的低地址端,低位字节排放在内存的高地址端。举一个例子,比如数字0x12 34 56 78在内存中的表示形式为:1)大端模式:低地址 -----------------> 高地址0x12 | 0x34 | 0x56 | 0x782)小...
阅读全文
摘要:13.9Write a smart pointer (smart_ptr) classtemplateclass SmartPoint{ public: SmartPoint(T *ref){ ref_ = ref; count_ = (unsigned int *)malloc(sizeof(unsigned int )); *count_ = 1; } SmartPoint(SmartPoint &sptr){ ref_ = sptr.ref_; count_ = sptr.count_; ++(*count_); } SmartPoint& operator =(Smar
阅读全文
摘要:转自:http://studytipsandtricks.blogspot.com/2012/05/15-most-important-differences-between-c.htmlBasic Introduce:C++ is derived from C Language. It is a Superset of C.Earlier C++ was known as C with classes.In C++, the major change was the addition of classes and a mechanism for inheriting class object
阅读全文
摘要:C++11 在类中引入了Move Constructor and the Move Assignmnt Operaetor,所谓‘move’指的是在复制对象时,left object 不用再创建资源,直接把right object 的资源当做自己的来用。而right object 的资源将全部被设置为default ,即为empty object 。http://blog.smartbear.com/c-plus-plus/c11-tutorial-introducing-the-move-constructor-and-the-move-assignment-operator/引入了关键字a
阅读全文