- 博客(6)
- 资源 (2)
- 收藏
- 关注
原创 绝不重新定义继承而来的函数的缺省参数值
首先,此处的函数指的是 virtual 函数,为什么不是non-virtual函数呢?是因为在public继承中,non-virtual函数表示派生类是需要继承其接口与其强制实现的。如果你的Derived已经在考虑重写non-virtual函数了,那么你是应该好好审视一下,在此处使用 public继承是否合理了。因此,本文只讲解virtual函数的缺省参数值,例如下面的代码:{CSDN
2014-06-24 20:11:50 1643
原创 C++ 标准库值操作迭代器的常见函数
迭代器是C++标准库中的重要组件,特别是在容器内部,没有迭代器,容器也就无所谓存在了。例如:vector容器简而言之就是3个迭代器 start finish 以及end_of_storage vector的任何操作都离不开这3个迭代器。。接下来,总结一下C++ 中的迭代器的操作。C++的迭代器分为5类,依次为 : Input_iterator, output_iterator,
2014-06-20 21:35:36 3800 1
原创 栈模拟队列 队列模拟栈
代码如下:PS:做了一些测试,目前没问题。有问题请指正。。。templateclass myQueue{private: stack push_stack; stack pop_stack;public: myQueue(){} ~myQueue(){} bool empty() const{return push_stack.empty(
2014-06-29 12:10:17 1132
原创 C++ 继承体系中的名称覆盖
首先一个简单的例子:int x;int f(){ double x; cin >> x; return x;}在上述代码中,函数f的局部变量x掩盖了全局变量x。这得从 “C++的名字查找机制“说起,首先,在函数f的局部作用域中查找,(甚至是语句块),如果不存在,到上一层的作用域再进行查找,... 该命名空间中查找,最后是全局作用域。在类的继承体系中
2014-06-22 15:24:27 1601
原创 Longest Common Prefix
题目描述:Write a function to find the longest common prefix string amongst an array of strings.很简单的一道题目,但是我写了两个不一样的版本,运行时间确实数倍之差。。贴代码如下:版本1:class Solution {public: string longestCommonPref
2014-06-09 21:06:19 984
原创 3 sum
3-sum 题目描述:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.题目要求:Elements
2014-06-01 11:46:00 2033 1
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人