diff --git a/include/rcp.h b/include/rcp.h index 5912a2a..896af56 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -292,7 +292,7 @@ rcp rcp_dynamic_cast(rcp && other) { \ return rcp_ref_count.load(std::memory_order_relaxed); \ } \ - template friend class rcp; \ + template friend class rcp; \ rcp_managed(classname) #define rcp_managed(classname) \ diff --git a/tests.cpp b/tests.cpp index 0f9d695..82159e5 100644 --- a/tests.cpp +++ b/tests.cpp @@ -413,6 +413,27 @@ void test_hash() assert(map.find(c) == map.end()); } +template +struct Box +{ + rcp_managed_root(Box); +protected: + Box(T v) : v(v) {} +public: + T v; +}; + +void test_class_template() +{ + auto a = Box::create(42); + auto b = Box::create(99); + assert(a->v == 42); + assert(b->v == 99); + auto c = a; + assert(c->v == 42); + assert(c.use_count() == 2); +} + void test_external_class() { int before = external_destruct; @@ -454,6 +475,7 @@ int main(int argc, char * argv[]) test_use_count(); test_swap(); test_hash(); + test_class_template(); test_external_class(); return 0; }