From 421a0725dd356cd7dc871c27b1049632065a30d2 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Fri, 25 May 2012 14:12:28 +0000 Subject: [PATCH] Added a default implementation of clone() for nonlinear factor so not all subclasses need to implement clone(). Default implementation throws an exception. --- gtsam/nonlinear/NonlinearFactor.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 2b7311306..bf6527599 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -157,8 +157,14 @@ public: /** * Creates a shared_ptr clone of the factor - needs to be specialized to allow * for subclasses + * + * By default, throws exception if subclass does not implement the function. */ - virtual shared_ptr clone() const =0; + virtual shared_ptr clone() const { + // TODO: choose better exception to throw here + throw std::runtime_error("NonlinearFactor::clone(): Attempting to clone factor with no clone() implemented!"); + return shared_ptr(); + } /** * Creates a shared_ptr clone of the factor with different keys using