From 015b1ee8079175cace17917d375d24175311b2f8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 9 Apr 2007 22:17:25 +0000 Subject: The SPtr is castable now. just say SPtrCast( ASPtr ); --- src/sptr.h | 15 +++++++++++++++ src/tests/sptr.cpp | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sptr.h b/src/sptr.h index 23c21dc..0ea8bca 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -4,9 +4,14 @@ #include #include +template class SPtr; +template< typename Tb, typename Ta > SPtr SPtrCast( SPtr src ); + template class SPtr { + template + friend SPtr SPtrCast( SPtr pt ); public: SPtr() : pRefCnt( NULL ), @@ -96,4 +101,14 @@ private: T *pData; }; +template< typename Tb, typename Ta > SPtr SPtrCast( SPtr src ) +{ + SPtr ret; + ret.pRefCnt = src.pRefCnt; + ret.pData = dynamic_cast(src.pData); + if( ret.pRefCnt ) + (*(ret.pRefCnt)) += 1; + return ret; +} + #endif diff --git a/src/tests/sptr.cpp b/src/tests/sptr.cpp index bc00f78..252463b 100644 --- a/src/tests/sptr.cpp +++ b/src/tests/sptr.cpp @@ -65,11 +65,12 @@ int main() beAnnoying( pt3 ); { - SPtr pt4( dynamic_cast >(pt3) ); + SPtr pt4( SPtrCast( pt3 ) ); printf("Count: %d\n", pt4.count() ); - pt4.go2(); + pt4->go2(); } + printf("Count: %d\n", pt.count() ); } printf("Count: %d\n", pt.count() ); } -- cgit v1.2.3