二级指针用在一维数组上
摘要:#include int main(){ int array_test[3]={1,2,3}; int **ptr; int i=0; ptr=(int**)&array_test;//这里必须要有强制类型转换 for(;i<3;i++) printf("%d\n",*(ptr+i)); return 0;}纯属娱乐~学习笔记。
阅读全文
构造函数的初始化列表
摘要:提倡使用初始化列表的方法而非在构造函数里进行赋值的方法。1、Temp::Temp(const string &fn):fistname(fn){}首先为firstname调用string的默认构造函数,在调用string的赋值运算符将firstname设置为fn2、Temp::Temp(const string &fn){ firstname=fn;}直接使用string的复制构造函数将firstname初始化为fn讲讲这些只是自娱自乐而已,就像是初次接触以下言论时候的心情一样:a[i] 与[i]a 是等价的,都可以编译通过而且在使用的时候完全等价。i++和i+=1之间的区别:
阅读全文
初尝new和delete的重载
摘要:new/delete分两种,一种是全局的,另一种是针对特定类的#include using namespace std;struct foo{ explicit foo( int val=0 ) : val_(val) {cout "; } int val_; static void* operator new[]( size_t size ); // 类形式的new/delete static void operator delete[]( void* raw );};char buf[1000];void* foo::operator new[]( size_t size ){
阅读全文