==> 在
weiha...@bbs.math.ncu.edu.tw (天天天藍) 的文章中提到:
> 【 在
mouse...@OfO.twbbs.org (ZZzzz....) 的大作中提到: 】
> then inside the global function func
> func ( A* PA ) {
> A* newA = PA->clone() ;
> list.add(newA) ;
> }
> The details can be found, of course, in
> More Effective C++ by Scott Meyers
Thanks! It's great answer for this question.
And I got another result from PaulLiu on CIS BBS of NCTU.
He has a slove this question by Template.
There is sample code.
template <class T> void func(T *pA)
{
A *newA = dynamic_cast < A *>(new T(*pA));
list.add(newA);
}
While we involve func(&b), we'll get Template function with T = B.
Alex Lee
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>