1.派生类定义一个新的实现。

2.派生类覆盖但是增加基类函数的功能(大多数情况)

 1 class TListNode;//前置声明
 2 class Tlist
 3 {
 4 public:
 5     virtual bool Append(void *newElementToAdd);
 6 };
 7 
 8 class TThreadSafeList :public Tlist
 9 {
10 public:
11     virtual bool Append(void *newElementToAdd);
12 };
13 
14 bool TThreadSafeList::Append(void *newElementToAdd)
15 {
16     //为了线程安全,执行一些步骤,锁定该对象。
17     //然后调用基类函数从后面添加新的元素
18     bool result = Tlist::Append(newElementToAdd);
19     //现在,通过对象解锁
20     return result;
21 }

 

posted on 2017-03-23 11:39  郑哲  阅读(147)  评论(0编辑  收藏  举报