- 博客(17)
- 收藏
- 关注
原创 c++学习笔记之 数组类与负数类
//////////////////////////////////////////////////////////////#ifndef ARRAY_H#define ARRAY_H#include #include #include #include #include #include class array{ public: //friend std::ostre
2014-09-27 23:44:11
430
原创 c++学习笔记之运算符重载与智能指针
ps::赋值操作会调用构造函数友元的位置 不在乎 public privates+=s2 s.operator+=(s2)
2014-09-26 23:31:58
499
原创 c++学习笔记之复制控制与stl算法
1、reverse迭代器在逻辑上,rbegin指向最后一个元素,rend指向第一个元素的前一个位置。但是在实际实现上,rbegin指向最后一个元素的下一个位置,rend指向第一个元素。reverse迭代器的物理位置与逻辑位置差1逻辑值比物理位置减少了1.采用这种实现的好处是:将iterator转化成reverse_iterator之后的区间,与之间的区间恰好相反,但内容相同。例
2014-09-25 18:50:10
366
原创 c++学习笔记之关联容器
1.pair不是容器,而是代表一个key-value键值对。2.map则是一个容器,里面存储了pair对象,只是存储的方式与vector这种连续存储,有所不同,map采用的是二叉排序树存储pair,一般是红黑树。3.map使用下标访问时,如果key不存在,那么会在map中添加一个新的pair,value为默认值。4.map的key必须具有小于操作符operato
2014-09-24 22:58:03
432
原创 c++学习笔记之vector容器与list容器
vector的几个跟容量有关的函数:size 元素数目,类似于会议室中人的数目resize 调整元素数目,类似于调整人数capacity 可容纳数目,类似会议室中的座位数量reserve 调整容量,增加或减少座位的数量vector的内存增长是按照成倍增长。vector与list区别:vector采用数组实现,list采用链表vector支持随机访问,list不提供下
2014-09-22 23:20:06
877
原创 c++学习笔记之迭代器
vector迭代器持续有效,除非:1.使用着在较小的索引位置插入或者删除元素。2.由于容量的变化引起的内存重新分配。list迭代器失效:将it指向的元素删除,那么it则失效用erase删除元素记得接收返回值,同时最好使用while循环。
2014-09-22 23:17:00
440
原创 c++学习笔记之static成员
使用static成员的注意事项:1static成员 类内声明,类外定义。static函数两种调用方式,(1)每个成员调用(2)类名调用 没用this指针 static不能调用成员函数内联函数不会带来函数开销
2014-09-22 22:58:30
486
原创 c++学习笔记之友元
#include #include #include using namespace std;class Test{ public: friend class Other; //声明Other是Test的朋友 friend void bar(const Test &t); private: int x_;
2014-09-22 22:47:35
523
原创 c++学习笔记之函数引用返回
#includeusing namespace std;#include#include#include#include#include #include #include string& test() { string s("hello"); return s; }int main(){ string ns; ns=test(); system("pau
2014-09-22 00:00:09
408
原创 c++学习笔记之类的static成员
#include #include #include using namespace std;class Test{ public : int a; static int b; public: Test(int _a,int _b):a(_a) { b=_b; }
2014-09-20 15:18:49
439
原创 c++学习笔记之c/c++两种语言初始化变量区别
#include int main(int argc, const char *argv[]){ int a; printf("%d",a); return 0;}这段代码是c代码,
2014-09-19 20:35:25
600
原创 c++学习笔记——一种非法的类型转换
#include #include #include using namespace std;int main(int argc, const char *argv[]){ double d = static_cast(12); size_t s = static_cast(d); //一下转换非法 int i; int *ptr = &i
2014-09-17 16:40:58
439
原创 c++学习笔记--异常处理
int main(int argc, const char *argv[]){ try { cout << "foo" << endl; throw std::runtime_error("exception ..."); cout << "bar" << endl; } catch(...) {
2014-09-17 16:20:25
647
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人