diff --git a/gtsam/base/GenericValue.h b/gtsam/base/GenericValue.h index 4fe5bc143..43f606a17 100644 --- a/gtsam/base/GenericValue.h +++ b/gtsam/base/GenericValue.h @@ -12,8 +12,8 @@ /* * @file GenericValue.h * @date Jan 26, 2012 - * @author Duy Nguyen Ta - * @author Mike Bosse, Abel Gawel, Renaud Dube + * @author Michael Bosse, Abel Gawel, Renaud Dube + * based on DrivedValue.h by Duy Nguyen Ta */ #pragma once @@ -117,7 +117,7 @@ public: /// equals implementing generic Value interface virtual bool equals_(const Value& p, double tol = 1e-9) const { // Cast the base class Value pointer to a templated generic class pointer - const This& genericValue2 = dynamic_cast(p); + const This& genericValue2 = static_cast(p); // Return the result of using the equals traits for the derived class return traits::equals(this->value_, genericValue2.value_, tol); @@ -140,7 +140,7 @@ public: /// Generic Value interface version of localCoordinates virtual Vector localCoordinates_(const Value& value2) const { // Cast the base class Value pointer to a templated generic class pointer - const This& genericValue2 = dynamic_cast(value2); + const This& genericValue2 = static_cast(value2); // Return the result of calling localCoordinates trait on the derived class return traits::localCoordinates(value_,genericValue2.value_); @@ -156,7 +156,7 @@ public: /// Assignment operator virtual Value& operator=(const Value& rhs) { // Cast the base class Value pointer to a derived class pointer - const This& derivedRhs = dynamic_cast(rhs); + const This& derivedRhs = static_cast(rhs); // Do the assignment and return the result this->value_ = derivedRhs.value_; diff --git a/gtsam/nonlinear/tests/testValues.cpp b/gtsam/nonlinear/tests/testValues.cpp index 5fbe4d6af..d77ecaf79 100644 --- a/gtsam/nonlinear/tests/testValues.cpp +++ b/gtsam/nonlinear/tests/testValues.cpp @@ -354,10 +354,12 @@ TEST(Values, filter) { if(i == 0) { LONGS_EQUAL(2, (long)key_value.key); try {key_value.value.cast();} catch (const std::bad_cast& e) { FAIL("can't cast Value to Pose2");} + THROWS_EXCEPTION(key_value.value.cast()); EXPECT(assert_equal(pose2, key_value.value.cast())); } else if(i == 1) { LONGS_EQUAL(3, (long)key_value.key); try {key_value.value.cast();} catch (const std::bad_cast& e) { FAIL("can't cast Value to Pose3");} + THROWS_EXCEPTION(key_value.value.cast()); EXPECT(assert_equal(pose3, key_value.value.cast())); } else { EXPECT(false);