Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ Polymophism¤U, «ü¼Ð©Ò«ü¸ê®Æªº½Æ»s°ÝÃD.

0 views
Skip to first unread message

反省

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
==> 在 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>

0 new messages