2012年10月30日

指针与引用的区别

摘要: string& rs; // 错误,引用必须被初始化 string s("xyzzy"); string& rs = s; // 正确,rs指向 s 指针没有这样的限制。 string *ps; // 未初始化的指针 // 合法但危险指针与引用的另一个重要的不同是指针可以被重新赋值以指向另一个不同的对象。 但是引用则总是指向在初始化时被指定的对象,以后不能改变。string s1("Nancy"); string s2("Clancy"); string& rs = s1; // rs ... 阅读全文

posted @ 2012-10-30 20:01 GIS-MAN 阅读(176) 评论(0) 推荐(0) 编辑

c++ 参数传递 之引用形参

摘要: 在函数内部对引用形参做 出的改变会影响到函数外部实参的改变引用形参的例子void swap(int &v1, int &v2) { int tmp = v2; v2 = v1; v1 = tmp; } 非引用形参void swap(int v1, int v2) { int tmp = v2; v2 = v1; // assigns new value to local copy of the argument v1 = tmp; }使用引用... 阅读全文

posted @ 2012-10-30 17:29 GIS-MAN 阅读(611) 评论(0) 推荐(0) 编辑

c++ 参数传递之 非引用形参

摘要: 1 非引用实参每次调用函数时,都会重新创建该函数所有的形参,此时所传递的实参将会初始化对应的形参。 形参的初始化与变量的初始化一样:如果形参具有非引用类型,则复制实参的值,如果形参为引用类型(第 2.5 节),则它只是实参的别名。指针形参————————————————可以修改实参指针指向的值,但是不能修改实参指针函数的形参可以是指针(第 4.2 节),此时将复制实参指针,如果函数形参是非 const 类型的指针,则函数可通过指针实现赋值,修改指针所指向对象的值:void reset(int *ip) { *ip = 0; // changes the value ... 阅读全文

posted @ 2012-10-30 17:20 GIS-MAN 阅读(370) 评论(0) 推荐(0) 编辑

c++ 枚举

摘要: 枚举成员值可以是不唯一的。 // point2d is 2, point2w is 3, point3d is 3, point3w is 4 enum Points { point2d = 2, point2w, point3d = 3, point3w }; 本例中,枚举成员 point2d 显式初始化为 2。下一个枚举成员 point2w 默认初始化,即它的值比前一枚举成员的值大 1。因此 point2w 初始化为 3。枚举成员 point3d 显式初始化为 3。一样,point3w 默认初始化,结果为 4。枚举的使用::Points pt3d = point3d; ... 阅读全文

posted @ 2012-10-30 16:47 GIS-MAN 阅读(164) 评论(0) 推荐(0) 编辑

c++ const

摘要: Const int bufSize=512// bufSize 以后不能修改,定义时必须初始化const std::string hi=“helloworld”在全局作用域声明的 const 变量是定义该对象的文件的局部变量。此变量只存在于那个文件中,不能被其他文件访问。通过指定 const 变更为 extern,就可以在整个程序中访问 const 对象:// file_1.cc // defines and initializes a const that is accessible to other files extern const int bufSize =... 阅读全文

posted @ 2012-10-30 16:42 GIS-MAN 阅读(170) 评论(0) 推荐(0) 编辑

c++ arrow operator ,, –> Operator,,,指针专属

摘要: C++ has an operator that can be used with a pointer to simplify the notation for specifying the members of a struct or a class. The arrow operator , -> , combines the actions of a dereferencing operator, * , and a dot operator to specify a member of a dynamic struct or class object that is p... 阅读全文

posted @ 2012-10-30 14:52 GIS-MAN 阅读(799) 评论(0) 推荐(0) 编辑

让c++ 函数返回一个数组

摘要: 在c++中是不允许数组作为函数的返回值的int [] someFunction( ); //ILLEGAL要想实现函数返回一个数组,那返回对应数组里面类型的指针you must return a pointer to the array base type and have the pointer point to the array. So, the function declaration would be as follows: int* someFunction( ); //Legalint* doubler( int a[], int size){int* temp = new in 阅读全文

posted @ 2012-10-30 14:45 GIS-MAN 阅读(45763) 评论(0) 推荐(0) 编辑

c++ const 修饰数组

摘要: //直接声明为 int a[], 这样会允许函数内部对a[] 进行修改void showTheWorld( int a[], int sizeOfa) { for ( int i = 0; i < sizeOfa; i++) cout << a[i] << " "; cout << endl; }如果 声明为const int a[], C++就不允许函数内部在对a[] ,进行修改了 void showTheWorld( const int a[], int sizeOfa) { ... 阅读全文

posted @ 2012-10-30 11:39 GIS-MAN 阅读(4797) 评论(0) 推荐(0) 编辑

c++ 数组

摘要: 声明: int a[6];声明时初始化 :允许不给数组的数量 int b[] = {5, 12, 11}; is equivalent to int b[3] = {5, 12, 11};函数里的数组: 阅读全文

posted @ 2012-10-30 11:03 GIS-MAN 阅读(147) 评论(0) 推荐(0) 编辑

c++ 继承

摘要: 单继承 多继承class ImageBook:public Book { } class ImageBook: public Book, public Image { };virtual inheritance ://li例子如下class Book :virtual public Paper { };class Image : virtual public Paper { }class ImageBook: public Book, public Image { };// 只会出现一个 Pa... 阅读全文

posted @ 2012-10-30 10:50 GIS-MAN 阅读(154) 评论(0) 推荐(0) 编辑

C++ 的对象模型

摘要: c++ 的数据字段模型也有两种一种是 static ,和nonestaticclass point(){public:point(int x);virtual -point();getOneangel();Static int pointCount()private:int x;static int xangel;}初始化一个point pt;看看内部构造 阅读全文

posted @ 2012-10-30 10:32 GIS-MAN 阅读(154) 评论(0) 推荐(0) 编辑

string 类型

摘要: c++ 里面的string就是一个char 数组char s[10] ,只能存9个字符,最后一个是\0char shortString[] = "abc";char shortString[] = {'a', 'b', 'c'}; 不同,————————》不是以\0结尾// 给一个数组赋值int index = 0;while ( (ourString[index] != "\0") && (index < SIZE) ) {ourString[index] = "X&quo 阅读全文

posted @ 2012-10-30 10:15 GIS-MAN 阅读(347) 评论(0) 推荐(0) 编辑

Vector 的学习

摘要: C++ 的数组运行时不能动态的改变数组的长度,但是 vector 可以vector<int> hellovector ,//是不是List<int>hellovector.push_back(10),hellovector.push_back(11),获取vector里面的数据for(int i=0;i<hellovector.size();i++){ cout<<hellovector(i);} 阅读全文

posted @ 2012-10-30 10:05 GIS-MAN 阅读(183) 评论(0) 推荐(0) 编辑

c++ 自定义类型

摘要: (1) 类型的声明class Daypfyear{public:Dayofyear(int month,int year);//声明构造函数Dayofyear();void input(int month);void getMonthNumber();private:int day;int month;}构造函数的实现;Dayofyear::Dayofyear(int month,int year){month=month;year=year;}Dayofyear::Dayofyear(int month){month=month;}构造函数的使用:Dayofyear oneDayofyear 阅读全文

posted @ 2012-10-30 09:51 GIS-MAN 阅读(360) 评论(0) 推荐(0) 编辑

c++ 学习文章

摘要: http://blog.csdn.net/degree_37/article/details/4060789C++内存对象大会战(转) 阅读全文

posted @ 2012-10-30 09:41 GIS-MAN 阅读(105) 评论(0) 推荐(0) 编辑

导航