posts - 61,comments - 5,views - 11万
04 2013 档案
函数指针
摘要:一、在学习arm过程中发现这“指针函数”与“函数指针”容易搞错,所以今天,我自己想一次把它搞清楚,找了一些资料,首先它们之间的定义:1、指针函数是指带指针的函数,即本质是一个函数。函数返回类型是某一类型的指针 类型标识符 *函数名(参数表) int *f(x,y);首先它是一个函数,只不过这个函数的返回值是一个地址值。函数返回值必须用同类型的指针变量来接受,也就是说,指针函数一定有函数返回值,而且,在主调函数中,函数返回值必须赋给同类型的指针变量。表示:float *fun();float *p;p = fun(a);注意指针函数与函数指针表示方法的不同,千万不要混淆。最简单的辨别方式就是看函 阅读全文
posted @ 2013-04-26 10:31 吉大依恋 阅读(170) 评论(0) 推荐(0) 编辑
常函数
摘要:类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态数据成员)作任何改变。在设计类的时候,一个原则就是对于不改变数据成员的成员函数都要在后面加 const,而对于改变数据成员的成员函数不能加 const。所以 const 关键字对成员函数的行为作了更加明确的限定:有 const 修饰的成员函数(指 const 放在函数参数表的后面,而不是在函数前面或者参数表内),只能读取数据成员,不能改变数据成员;没有 const 修饰的成员函数,对数据成员则是可读可写的。除此之外,在类的成员函数后面加 const 还有什么好处呢?那就是常量(即 const)对象可以调用 阅读全文
posted @ 2013-04-26 10:30 吉大依恋 阅读(1091) 评论(0) 推荐(0) 编辑
原生指针auto_ptr的用法
摘要:原生指针auto_ptr在头文件<memory>中,auto_ptr角括号内放的是“原生指针所指对象”的型别,而不是原生指针的型别。auto_ptr如下用法,和原生指针一模一样:#include<iostream>#include<string>#include<memory>using namespace std;void func(){ auto_ptr<string> ps(new string("jjhou")); cout<<*ps<<endl;//输出jjhoucout<& 阅读全文
posted @ 2013-04-26 10:04 吉大依恋 阅读(331) 评论(0) 推荐(0) 编辑
explicit的作用
摘要:简单说就是用在构造函数前面 禁止隐式类型转换比如class cls{explicit cls(int i){...}};另外有一个函数void f(cls obj){...}int i=0;这时候调用f(i)就是错误的没有explicit的话就可以用i隐式建立一个对象这样做(显示调用构造函数)就是对的:cls obj(i); 阅读全文
posted @ 2013-04-26 09:55 吉大依恋 阅读(213) 评论(0) 推荐(0) 编辑
临时对象的产生与运用
摘要:#include<iostream>#include<vector>#include<algorithm>using namespace std;template <typename T>class print{public:void operator()(const T& elem){ cout<<elem<<' ';}};int main(){int ia[6]={0,1,2,3,4,5};vector<int> iv(ia,ia+6);for_each(iv.begin(),iv. 阅读全文
posted @ 2013-04-23 10:37 吉大依恋 阅读(164) 评论(0) 推荐(0) 编辑
自增自减操作符
摘要:#include<iostream>using namespace std;class INT{friend ostream& operator<<(ostream& os,const INT& i);public:INT(int i):m_i(i){};//prefix ++INT& operator++(){ ++(this->m_i);return *this;}//postfix ++const INT operator++(int){ INT temp=*this; ++(*this); return temp;}//pr 阅读全文
posted @ 2013-04-23 10:35 吉大依恋 阅读(168) 评论(0) 推荐(0) 编辑
function call 操作符
摘要:#include<iostream>using namespace std;int fcmp(const void* elem1,const void* elem2){ const int* i1=(const int*)elem1; const int* i2=(const int*)elem2; return (*i1-*i2);}int main(){int ia[10]={32,92,67,58,10,4,25,52,59,54};for(int i=0;i<10;i++){ cout<<ia[i]<<" ";}cout&l 阅读全文
posted @ 2013-04-23 10:34 吉大依恋 阅读(220) 评论(0) 推荐(0) 编辑
重载operator()
摘要:#include<iostream>using namespace std;template<class T>struct plus{ T operator()(const T& x,const T& y) const{ return x+y;}};template<class T>struct minus{ T operator()(const T& x,const T& y) const { return x-y; }};int main(){ plus<int> plusobj;minus<int> 阅读全文
posted @ 2013-04-23 10:32 吉大依恋 阅读(290) 评论(0) 推荐(1) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示