摘要:
在继承一个virtual函数的时候,如果这个virtual函数同样是有默认值的话,那么其表明这次继承既存在动态绑定也存在静态绑定:例如下面这个例子: 1 class Shape{ 2 public: 3 enum shapeColor{red, green, blue}; 4 vir... 阅读全文
posted @ 2015-10-18 16:57
eversliver
阅读(389)
评论(0)
推荐(0)
摘要:
重新定义一个继承而来的non-virtual函数可能会使得导致当函数被调用的时候,被调用的函数不是取决于调用的函数究竟属于的对象,而是取决于调用函数的指针或者引用的类型。所以一般的说主要有两种观点在这方面:1. 如果D非要重新继承而来的函数的话,那么说明他们的关系可能是不适合public继承的,因为... 阅读全文
posted @ 2015-10-18 16:56
eversliver
阅读(409)
评论(0)
推荐(0)
摘要:
有一部分人总是主张virtual函数几乎总应该是private:例如下面这个例子,例子时候游戏,游戏里面的任务都拥有健康值这一属性:class GameCharacter{public: int healthValue()const{ ... int retVal ... 阅读全文
posted @ 2015-10-18 16:55
eversliver
阅读(441)
评论(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
阅读(367)
评论(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
阅读(320)
评论(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
阅读(457)
评论(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
阅读(265)
评论(0)
推荐(0)

浙公网安备 33010602011771号