From 7db1e6d50594b47a32ecca5a349a4e8540f890c0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 15 Dec 2008 11:40:24 +0000 Subject: [PATCH] Add copy constructor and copy assignment to Variant --- source/core/variant.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/core/variant.h b/source/core/variant.h index 6425fbf..6632831 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -19,6 +19,7 @@ private: struct StoreBase { virtual ~StoreBase() { } + virtual StoreBase *clone() const =0; }; template @@ -27,6 +28,7 @@ private: T data; Store(T d): data(d) { } + virtual StoreBase *clone() const { return new Store(data); } }; StoreBase *store; @@ -35,6 +37,7 @@ public: Variant(): store(0) { } template Variant(const T &v): store(new Store::Type>(v)) { } + Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } ~Variant() { delete store; } template @@ -45,6 +48,13 @@ public: return *this; } + Variant &operator=(const Variant &v) + { + delete store; + store=(v.store ? v.store->clone() : 0); + return *this; + } + template T &value() const { -- 2.43.0