From 6e603b412fcc11c550d09eb2e484530db6f0c0a4 Mon Sep 17 00:00:00 2001 From: David Vereb Date: Fri, 10 Nov 2017 15:42:32 -0500 Subject: [PATCH] Not sure how to keep Type out of the template while still referencing it from the templated class. i.e. How would I do this: "DualLookup::Type"? --- DualLookup.h | 14 ++++++++++---- main.cpp | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/DualLookup.h b/DualLookup.h index 4015dfe..73cf91f 100644 --- a/DualLookup.h +++ b/DualLookup.h @@ -2,11 +2,8 @@ #define DVEREB_DUALLOOKUP_H #include -template -class DualLookup { -public: - DualLookup(); +struct DualLookupBase { // NOTE(dev): Used to determine which version of the string you want: // 1 / OPPOSITE: The string it maps to, opposite of the one you pass in. // 2 / VALUE: The string passed via the first paramater of 'add.' @@ -17,6 +14,15 @@ public: EQUIVALENT, }; +protected: + DualLookupBase() {} +}; + +template +class DualLookup : public DualLookupBase { +public: + DualLookup(); + /* Add a mapped pair to the container * returns false if it already exists, regardless of direction * (i.e. value->equivilent is a duplicate of equivilent->value) diff --git a/main.cpp b/main.cpp index 240b74a..a4de7a2 100644 --- a/main.cpp +++ b/main.cpp @@ -65,13 +65,13 @@ TEST_CASE("all tests", "all") { REQUIRE(container.get(1, container_result)); CHECK(container_result == 2); container_result = 0; - REQUIRE(container.get(1, container_result, DualLookup::Type::OPPOSITE)); + REQUIRE(container.get(1, container_result, DualLookupBase::Type::OPPOSITE)); CHECK(container_result == 2); container_result = 0; - REQUIRE(container.get(1, container_result, DualLookup::Type::EQUIVALENT)); + REQUIRE(container.get(1, container_result, DualLookupBase::Type::EQUIVALENT)); CHECK(container_result == 2); container_result = 0; - REQUIRE(container.get(1, container_result, DualLookup::Type::VALUE)); + REQUIRE(container.get(1, container_result, DualLookupBase::Type::VALUE)); CHECK(container_result == 1); container_result = 0;