Posts

Showing posts with the label virtual-destructor

valgrind shows memory leak in std::make_unique

I'm using valgrind to check for memory leaks. Unfortunately I get a Leak_DefinitelyLost warning. Attached is a simplified version of my code that reproduces the error: #include <iostream> #include <vector> #include <memory> #include <unordered_map> using namespace std; class Base{ public: explicit Base(double a){ a_ = a; } virtual void fun() = 0; protected: double a_; }; class Derived_A : public Base{ public: Derived_A(double a, vector<double> b, vector<double> c): Base(a), b_{b}, c_{c}{ } void fun() override{ cout << "Derived_A " << a_ << endl; } private: vector<double> b_; vector<double> c_; }; class Derived_B : public Base{ public: Derived_B(double a, double b, double c): Base(a), b_{b}, c_{c}{ } void fun() override{ cout << "Derived_B " << a_ << endl; } private: double b_; double c_; }; in...