1. bool operator mylist; std::list::iterator iter; S a; a.firstname ="dfadf"; a.ID = 5; mylist.push_back (a); a.firstname ="得到"; a.ID = 9;...
分类:
编程语言 时间:
2014-10-25 14:27:37
阅读次数:
279
Divide Two IntegersDivide two integers without using multiplication, division and mod operator.SOLUTION 11. 基本思想是不断地减掉除数,直到为0为止。但是这样会太慢。2. 我们可以使用2分法来加...
分类:
其他好文 时间:
2014-10-24 22:02:06
阅读次数:
279
The remainder function and % operator.
下面这段代码过不了编译的(gcc)
#include
#include
int main()
{
double x = 10;
printf("x % 2 = %lf\n",x%2.0);
return 0;
}
operator % 仅能操作在整形数...
分类:
其他好文 时间:
2014-10-23 17:46:23
阅读次数:
195
1、new调用了构造函数,delete调用了析构函数? 实际上这是一个错误的想法。
2、new确实是对malloc进行了包装,看不到源码,我们只能猜测一下,C++标准库中规定的operator new 操作有没有调用构造函数?我也还不知道。唯一正确就是"operator new typename(parameter) "实际上是分解为三个步骤:
看懂这句话就可以啦。operator new /*参数1:*/ typename ( /*"参数2 为:typename调用构造函数的参数,不是new 操作的“...
分类:
其他好文 时间:
2014-10-22 06:27:22
阅读次数:
205
题目链接:http://poj.org/problem?id=1442思路:维护一个最小堆与最大堆,最大堆中存储最小的K个数,其余存储在最小堆中代码:#include#includeusing namespace std;struct cmp1{ bool operator() ( cons...
分类:
其他好文 时间:
2014-10-22 00:26:42
阅读次数:
223
class _string{public: _string(const char* str=NULL); _string(const _string& another); ~_string(); _string& operator=(const _string & rhs);...
分类:
其他好文 时间:
2014-10-21 16:54:27
阅读次数:
205
1、当变量i的数据类型是c++语言默认提供的类型的话,他们的效率是一样的。从其汇编执行的条数是一样的,所以其执行效率是一样的(有兴趣可以用gdb查看汇编代码)2、我们自定的数据类型,++i效率高于i++,通过运算符重载来给大家说明这一点。Operator Operator::operator++()...
分类:
编程语言 时间:
2014-10-21 10:13:12
阅读次数:
180
Divide two integers without using multiplication, division and mod operator.分析:题目意思很容易理解,就是不用乘除法和模运算求来做除法,很容易想到的一个方法是一直做减法,然后计数,超时。在网上找到一种解法,利用位运算,意思是...
分类:
其他好文 时间:
2014-10-21 02:10:36
阅读次数:
185
Divide two integers without using multiplication, division and mod operator.分析:不能用乘、除、取模运算,我们可以用的运算还有加、减、位运算。一个比较简单的想法是在dividend上不断减去divisor,知道余数小于div...
分类:
其他好文 时间:
2014-10-20 21:18:28
阅读次数:
183
什麽時候需要覆蓋Equals?自定義的值類型需要覆蓋,因爲系統默認的實現是基於反射的,效率不高。自定義的引用類型要根據業務需要來決定是否提供覆蓋。什麽時候需要覆蓋operator==()?自定義的值類型需要覆蓋,原因和Equals一樣。自定義的引用類型一般不要覆蓋,因爲框架的默認語義是按引用比較。如...
分类:
其他好文 时间:
2014-10-20 19:10:12
阅读次数:
133