From 92312a5ab76a934f3e79896722d8ec46deffb233 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 9 Apr 2007 21:59:54 +0000 Subject: david - i need to cast a sptr... started writing test for it --- src/tests/sptr.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/tests/sptr.cpp b/src/tests/sptr.cpp index 38d3675..bc00f78 100644 --- a/src/tests/sptr.cpp +++ b/src/tests/sptr.cpp @@ -9,12 +9,12 @@ public: printf("Created.\n"); } - ~Annoy() + virtual ~Annoy() { printf("Destroyed.\n"); } - void go() + virtual void go() { printf("%d: I'm annoying.\n", ++nCnt); } @@ -22,6 +22,22 @@ public: int nCnt; }; +class Annoy2: public Annoy +{ +public: + Annoy2(){}; + virtual ~Annoy2(){}; + virtual void go() + { + printf("{{I'm Annoy2!!}} "); + Annoy::go(); + } + virtual void go2() + { + printf("This is me, on my own...\n"); + } +}; + void beAnnoying( SPtr bob ) { printf("bob-Count: %d\n", bob.count() ); @@ -30,7 +46,7 @@ void beAnnoying( SPtr bob ) int main() { - SPtr pt( new Annoy ); + SPtr pt( new Annoy2 ); printf("Count: %d\n", pt.count() ); pt->go(); @@ -47,6 +63,13 @@ int main() pt3->go(); beAnnoying( pt3 ); + + { + SPtr pt4( dynamic_cast >(pt3) ); + printf("Count: %d\n", pt4.count() ); + + pt4.go2(); + } } printf("Count: %d\n", pt.count() ); } -- cgit v1.2.3