diff --git a/include/rcp.h b/include/rcp.h index 9876e24..2280b8e 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -90,6 +90,11 @@ public: return ptr; } + T & operator*() const + { + return *ptr; + } + bool operator!() const { return !ptr; diff --git a/test/tests.cpp b/test/tests.cpp index 0da1698..7e9186a 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -13,6 +13,8 @@ class MyBase protected: MyBase(int x, int y) { + this->x = x; + this->y = y; mybase_construct++; } @@ -20,6 +22,10 @@ protected: { mybase_destruct++; } + +public: + int x; + int y; }; class MyDerived : public MyBase @@ -29,6 +35,7 @@ class MyDerived : public MyBase protected: MyDerived(double v) : MyBase(1, 2) { + this->v = v; myderived_construct++; } @@ -36,20 +43,35 @@ protected: { myderived_destruct++; } + +public: + double v; }; -void t1() +void test_destructors_called() { - rcp mybase = MyBase::create(4, 5); - rcp myderived = MyDerived::create(42.5); -} - -int main(int argc, char * argv[]) -{ - t1(); + { + rcp mybase = MyBase::create(4, 5); + rcp myderived = MyDerived::create(42.5); + } assert(mybase_construct == 2); assert(mybase_destruct == 2); assert(myderived_construct == 1); assert(myderived_destruct == 1); +} + +void test_dereference() +{ + rcp mybase = MyBase::create(2, 3); + assert(mybase->x == 2); + assert(mybase->y == 3); + assert((*mybase).x == 2); + assert((*mybase).y == 3); +} + +int main(int argc, char * argv[]) +{ + test_destructors_called(); + test_dereference(); return 0; }