码迷,mamicode.com
首页 >  
搜索关键字:operator overloading    ( 3732个结果
STL函数对象和Lambda表达式
STL函数对象和Lambda表达式1.基本概念Function object是定义了operator()的object。FunctionObjectType fo;fo(…);调用函数对象的operator()代替函数fo()的调用。等价于:fo.operator()(…);函数对象的三个好处:(1...
分类:其他好文   时间:2014-07-11 09:59:40    阅读次数:182
Lists are mutable
The syntax for accessing the elements of a list is the same as for accessing the characters of a string – the bracket operator ([ ]). The expression i...
分类:其他好文   时间:2014-07-11 08:55:10    阅读次数:174
C++模板实现单向链表
模板实现头文件:#ifndef SUN_LINKLIST_H#define SUN_LINKLIST_H#include using namespace std ;//#include "List.h"// T : operator= , operator!= , operator== , cop....
分类:编程语言   时间:2014-07-10 16:23:14    阅读次数:220
记录以下boost::shared_ptr的一个使用细节
shared_ptr::operator->返回的是T*类型指针,非const T*指针。因此通过const shared_ptr&类型的ptr可以直接调用T各个原始的方法,不用担心const与非const问题。具体shared_ptr::operator->实现如下,摘自boost1.52.0版本...
分类:其他好文   时间:2014-07-09 23:34:42    阅读次数:194
c++ string assign =
C++ string类的成员函数,用于拷贝、赋值操作,它们允许我们顺次地把一个string 对象的部分内容拷贝到另一个string 对象上。string &operator=(const string &s);把字符串s赋给当前字符串string &assign(const char *s);用c类...
分类:编程语言   时间:2014-07-09 23:22:50    阅读次数:287
整形提升(c语言基础)
When you use an arithmetic operator, the operands go through two conversions.Integer promotions: If int can represent all values of the type, then the...
分类:编程语言   时间:2014-07-09 13:46:00    阅读次数:278
C++学习笔记32 谓词函数
首先来看看百度百科对"谓词函数"的定义说明: 1定义编辑 一个判断式,一个返回bool值的函数或者仿函数。几元就是函数有几个参数,至于定义和使用,函数定义和一般的函数定义一样,仿函数就是写个类,然后重载operator()。使用就是在那些以这种需要返回bool值的函数作参数的函数里用了。 一元谓词函数举例如下 1,判断给出的string对象的长度是否小于6 boo...
分类:编程语言   时间:2014-07-09 13:01:39    阅读次数:213
operator= 复制操作符的意外
首先,看下面的代码的输出时什么: 上述代码做了最理所当然的事,就是将Derived的两个对象进行了交换。但是通过指针进行的赋值输出却不是预期的: 竟然调用的是Base的operator=,也就意味着我们把d2的Base部分赋值给了d1,而现在的d1就是 “一般是自己的derived,一半是d2的Base”的怪物啦!!! 看来编译器没有理会我们的意图,...
分类:其他好文   时间:2014-07-09 12:23:19    阅读次数:194
effective c++ 条款10 handle assignment to self operator =
非强制性,但是个好习惯当使用连锁赋值时很有用x=y=z=10;class Window{ public: Window& operator=(int size) { ... return *this; }}这个规则适用于 -,+, +=,-= etc
分类:编程语言   时间:2014-07-06 16:14:49    阅读次数:264
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.思路:不能使用乘法除法以及取模运算来计算两个数相除。主要做法就是,将因子不断乘2(向左移位即可实现),同时结果从1不断移位加倍,等到除数大于被除数一...
分类:其他好文   时间:2014-07-06 15:34:24    阅读次数:197
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!