深拷贝和浅拷贝

摘要: 浅拷贝(当遇到指针变量时会出错!!)#include "iostream"using namespace std;class A{public: A() { x=new int; *x=5; } ~A() { delete x; x=NULL; } A(const A&a) { cout<<"拷贝构造函数执行中"<<endl; x=new int; *x=*(a.x); } void print() { cout<<*x<<endl; } void set(int i) { *x=i; }priva 阅读全文
posted @ 2012-08-29 10:21 ++小客 阅读(125) 评论(0) 推荐(0)

前置运算符和后置运算符的区别

摘要: #include "iostream"using namespace std;class test{public: test() { n=1; cout<<"无参数的构造函数在执行!"<<endl; } test(int i) { n=i; cout<<"有参数的构造函数在执行!"<<endl; } test(const test&a) { n=a.n; cout<<"拷贝构造函数在执行!"<<endl; } ~test() { cou 阅读全文
posted @ 2012-08-29 09:46 ++小客 阅读(1407) 评论(0) 推荐(0)

位操作符

摘要: 1、~位求反。2、<<左移 >>右移。3、&位与。 当两个都是1时则为1,否则为0. | 位或。 当有一个或两个为1时就为1,两个都是0为0. ^位异或。 当两个一个为0一个为1时为1,否则为0. 阅读全文
posted @ 2012-08-28 11:13 ++小客 阅读(114) 评论(0) 推荐(0)

指针与const

摘要: 1、指向const对象的指针。 const int *a; //定义了一个指向const对象的指针。不可以通过a来进行初始化。也不可以将一个const对象的变量付给一个非指向const的指针。 比如: *a=6;是错误----------------------------------------------------------------------------- const double pi=3.14; double *p=&pi; 是错误的。------------------------------------------------------... 阅读全文
posted @ 2012-08-28 09:49 ++小客 阅读(132) 评论(0) 推荐(0)

vector+iterator

摘要: void main(){ vector<int> v; //这里的vector相当于一个动态数组。可以实现C语言里面的链表的功能。很强大。 vector<int>::iterator it;//定义迭代器 int i; while(cin>>i) { v.push_back(i);//将输入的i值放入v中 } for(it=v.begin();it!=v.end();it++)//使用迭代器将其输出。 { cout<<*it<<endl; }} 阅读全文
posted @ 2012-08-27 17:00 ++小客 阅读(176) 评论(0) 推荐(0)

VS2008批量注释一段代码

摘要: 先按下ctrl+k再按下ctrl+c即可! 阅读全文
posted @ 2012-08-27 16:53 ++小客 阅读(337) 评论(0) 推荐(0)

初始化vector

摘要: 不可以像数组一样数组那样初始化。int a[]={1,2,3,4}; vector<int> v(a,a+4); 阅读全文
posted @ 2012-08-27 16:47 ++小客 阅读(140) 评论(0) 推荐(0)

fatal error LNK1168: cannot open xxx.exe for writing

摘要: 解决 此问题的方法是,打开资源管理器。将xxx.exe终止即可! 阅读全文
posted @ 2012-08-27 16:44 ++小客 阅读(124) 评论(0) 推荐(0)