上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 29 下一页
摘要: 在继承一个virtual函数的时候,如果这个virtual函数同样是有默认值的话,那么其表明这次继承既存在动态绑定也存在静态绑定:例如下面这个例子: 1 class Shape{ 2 public: 3 enum shapeColor{red, green, blue}; 4 vir... 阅读全文
posted @ 2015-10-18 16:57 eversliver 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 重新定义一个继承而来的non-virtual函数可能会使得导致当函数被调用的时候,被调用的函数不是取决于调用的函数究竟属于的对象,而是取决于调用函数的指针或者引用的类型。所以一般的说主要有两种观点在这方面:1. 如果D非要重新继承而来的函数的话,那么说明他们的关系可能是不适合public继承的,因为... 阅读全文
posted @ 2015-10-18 16:56 eversliver 阅读(381) 评论(0) 推荐(0) 编辑
摘要: 有一部分人总是主张virtual函数几乎总应该是private:例如下面这个例子,例子时候游戏,游戏里面的任务都拥有健康值这一属性:class GameCharacter{public: int healthValue()const{ ... int retVal ... 阅读全文
posted @ 2015-10-18 16:55 eversliver 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 在普通的public继承中,实际上也分为接口以及实现继承。首先看下面这个例子: 1 class Shape{ 2 public: 3 virtual void draw() const = 0; 4 virtual void error(const std::string & msg... 阅读全文
posted @ 2015-10-18 16:53 eversliver 阅读(344) 评论(0) 推荐(0) 编辑
摘要: 首先看下下面这个例子:class Base{private: int x;public: virtual void mf1() = 0; virtual void mf2(); void mf3(); ...};class Derived : public Base{p... 阅读全文
posted @ 2015-10-18 16:51 eversliver 阅读(300) 评论(0) 推荐(0) 编辑
摘要: Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2015-10-18 11:26 eversliver 阅读(428) 评论(0) 推荐(0) 编辑
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-10-18 10:19 eversliver 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference betweennums[i]andnums[j]is at mo... 阅读全文
posted @ 2015-10-17 16:05 eversliver 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the differe... 阅读全文
posted @ 2015-10-17 14:41 eversliver 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文
posted @ 2015-10-17 13:09 eversliver 阅读(258) 评论(0) 推荐(0) 编辑
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 29 下一页