moved doc/examples to examples according to new build process

This commit is contained in:
Marc Wäckerlin
2015-03-17 12:58:27 +00:00
parent a729670ba7
commit 6d91c244c2
11 changed files with 139 additions and 10 deletions

26
examples/smartpointer.cxx Normal file
View File

@@ -0,0 +1,26 @@
#include <mrw/smartpointer.hxx>
class A {
public: int a;
public: virtual ~A() {}
protected: virtual void fn() {} // dynamic_cast requires a virtual function
};
class B: virtual public A {
public: int b;
};
int main(int, char**) {
mrw::SmartPointer<int> i1 = new int;
*i1 = 13;
mrw::SmartPointer<int> i2 = i1;
mrw::SmartPointer<int> i3;
if (!i3) i3 = i2;
*i2 = 666; // *i1 is now 666 too
mrw::SmartPointer<A> b1 = new B;
mrw::SmartPointer<B> b2 = b1; // b1 and b2 point to the same instance
b1->a = 0; // b1->b does not compile
b2->a = 1;
b2->b = 2;
return 0;
} // memory is automatically freed