From a15cf65c44d5c224169c32ef5495b68c758134b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 18 May 2014 16:08:14 +0200 Subject: Imported Upstream version 3.3.0.2 --- libcult/examples/mm/shptr/shptr.cxx | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 libcult/examples/mm/shptr/shptr.cxx (limited to 'libcult/examples/mm/shptr/shptr.cxx') diff --git a/libcult/examples/mm/shptr/shptr.cxx b/libcult/examples/mm/shptr/shptr.cxx new file mode 100644 index 0000000..cb026d4 --- /dev/null +++ b/libcult/examples/mm/shptr/shptr.cxx @@ -0,0 +1,73 @@ +// file : examples/mm/shptr/shptr.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Boris Kolpackov +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include // MM::locate +#include // MM::inc_ref + +#include + +using std::cerr; +using std::endl; + +using namespace Cult; +using namespace MM; + +struct Foo +{ + virtual ~Foo () {} + char c; +}; + +struct Bar: virtual Foo {char c;}; + +struct Baz: virtual Foo {char c;}; + +struct Fox: Bar, Baz {}; + + +struct A +{ + char c[8]; +}; + +struct B +{ + char c[8]; +}; + +struct C : A, B +{ + char c[8]; +}; + +int +main () +{ + { + Baz* bp (new Fox); + Foo* fp (bp); + + Counter* cp (locate (fp, *counted)); + + inc_ref (bp); + + cp->dec_ref (); + + if (cp->dec_ref ()) cerr << "good: destroying" << endl; + else cerr << "bad: leaking" << endl; + + delete bp; + } + + { + Shptr pfox (new Fox); + Shptr pbar (pfox); + + Shptr pfoo; + + pfoo = pbar; + } +} -- cgit v1.2.3