
C++
文章平均质量分 55
juary_01
一个菜鸟成长的记录
展开
-
c++ primer学习笔记-2变量与基本类型
引用与指针: 指针与引用都能提供对其他对象的原创 2014-11-05 00:28:39 · 519 阅读 · 0 评论 -
友元函数和友元类
1.概述友元提供了一种 普通函数或者类成员函数 访问另一个类中的私有或保护成员 的机制。也就是说有两种形式的友元:(1)友元函数:普通函数对一个访问某个类中的私有或保护成员。(2)友元类:类A中的成员函数访问类B中的私有或保护成员。2.特性优点:提高了程序的运行效率。缺点:破坏了类的封装性和数据的透明性。3.实现转载 2016-06-22 15:51:45 · 257 阅读 · 0 评论 -
C++命名空间
一、 为什么需要命名空间(问题提出) 命名空间是ANSIC++引入的可以由用户命名的作用域,用来处理程序中 常见的同名冲突。 在 C语言中定义了3个层次的作用域,即文件(编译单元)、函数和复合语句。C++又引入了类作用域,类是出现在文件内的。在不同的作用域中可以定义相同名字的变量,互不于扰,系统能够区别它们。 1、全局变量的作用域是整个程序,在同一转载 2016-06-22 09:25:32 · 320 阅读 · 0 评论 -
c++ primer 学习笔记8--函数指针
书P223页,练习 6.54编写4个函数,分别对两个int值,执行加,减,乘,除运算,调用vector对象中的每个元素,输出结果。#include #include using namespace std;int func1(int a, int b){ return a + b;}int func2(int a, int b){ return a - b;}in原创 2015-04-09 17:00:14 · 477 阅读 · 0 评论 -
c++ primer 学习笔记5--编写头文件
书本186页:包含前面的函数声明习题6.8#ifndef CHAPTER6_H_INCLUDED#DEFINE CHApter6_h_INCLUDEDint fact(int i);double myABS(double);double myADD(double);#endif //CHAPTER6_H_INCLUDED原创 2015-04-09 15:07:57 · 392 阅读 · 0 评论 -
c++ primer 学习笔记7--函数返回声明
书本206页,练习6.36编写一个函数声明,使其返回数组的引用,并且该数组包含10个string对象1. string (*func())[10];2.使用类型别名:typedef string sPtr[10];//or using sPtr=string[10];sPtr &func();3.使用decltype关键字string str[10];原创 2015-04-09 16:14:17 · 474 阅读 · 0 评论 -
c++ primer 学习笔记6--交换两个int指针
书本196页 练习6.22#include using namespace std;//该函数既不叫好指针,也不交换指针所指的内容//所有改变局限在函数内部void swap1(int *p, int *q){ int *temp = p; p = q; q = temp;}//该函数交换指针所指内容//同样以值传递的方式使用指针,但是在函数内部通过解引用的方式直接原创 2015-04-09 15:50:15 · 1166 阅读 · 0 评论 -
c++ primer 学习笔记 4
书164页,统计含有两个字符的字符序列的数量:#include #include #include using namespace std;int main(){ unsigned ffcnt = 0,ficnt =0, flcnt = 0; char ch,c='\0'; cout << "请依次输入数: " << endl;原创 2015-04-09 14:42:51 · 418 阅读 · 0 评论 -
c++ primer 学习笔记11--动态内存
书本411页。练习12.6:编写函数,返回一个动态分配的int的vector。将此vector传递给另一个函数,这个函数读取标准输入,将输入的值保存在vector元素中,再将vector传递给另一个函数,打印输入的值。记得在恰当的时候delete vector。#include #include using namespace std;vector *new_vector(voi原创 2015-04-14 09:51:54 · 390 阅读 · 0 评论 -
c++ primer 学习笔记10--关联容器
书本376页。练习11.4:单词计数,忽略大小写,与标点。#include #include #include #include #include #include using namespace std;string& trans(string &s){ for (int p = 0; p < s.size(); ++p) { if (s[p] >= 'A'&&原创 2015-04-12 14:42:29 · 438 阅读 · 0 评论 -
c++ primer 学习笔记12--拷贝赋值,销毁
书本447页:13.13#include #include using namespace std;struct X{ X(){ cout << "构造函数X()" << endl; } X(const X&){ cout << "拷贝构造函数X(const X&)" << endl; } X& operator=(const X&){ cout << "拷贝赋值运算符=(co原创 2015-04-19 21:34:10 · 540 阅读 · 0 评论 -
c++ primer 学习笔记9--文件输入输出
书285页,练习8.4#include #include #include #include using namespace std;int main(){ ifstream in("data.txt"); if (!in) { cerr << "无法打开输入文件" << endl; return -1; } string line; vector wor原创 2015-04-11 12:32:46 · 532 阅读 · 0 评论 -
c++ primer 学习笔记13--模板
书本583页:16.6接受一个数组实参的biao原创 2015-04-22 12:12:37 · 501 阅读 · 0 评论 -
c++ primer学习笔记3-标准库类型string&vector
1.string 与getline原创 2014-11-05 10:11:48 · 579 阅读 · 0 评论 -
c++ primer学习笔记-1
书上15页的第一个小程序:原创 2014-11-04 23:40:40 · 604 阅读 · 0 评论 -
函数指针和回调函数
C++很多类库都喜欢用回调函数,MFC中的定时器,消息机制,hook机制等待,包括现在在研究的cocos2d-x中也有很多的回调函数。1.回调函数什么是回调函数呢?回调函数其实就是一个通过函数指针调用的函数!假如你把A函数的指针当作参数传给B函数,然后在B函数中通过A函数传进来的这个指针调用A函数,那么这就是回调机制。A函数就是回调函数,而通常情况下,A函数是系统在符合你设转载 2016-06-22 20:51:10 · 247 阅读 · 0 评论