代碼如下:
RCIPtr.h





































RCIPtr.cpp










































































































RCObject.h





























RCObject.cpp



























































Widget.h
























Widget.cpp

















































RCWidget.h





















RCWidget.cpp






























test.cpp





















Result :
Size of this Widget is 100
Size of this Widget is 100
v RCWidget RefCount is 2
w RCWidget RefCount is 2
Size of this Widget is 20
Size of this Widget is 100
v RCWidget RefCount is 1
w RCWidget RefCount is 1
Press any key to continue
只要每次寫一個類似的RC類,就不用修改客戶端已有的類,而又可以實現Reference-Counting了