virtual-destructor

error LNK2019 - Virtual destructor in abstract class [duplicate]

烈酒焚心 提交于 2019-12-30 11:16:09
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Pure virtual destructor in C++ I have two classes: the abstract "Game" class and the derived "TestGame" class. All of the functions in TestGame are implemented separately to nothing (for the sake of getting it to compile). I am only getting one error: TestGame.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Game::~Game(void)" (??1Game@@UAE@XZ) referenced in function "public: virtual _

Is there a use for making a protected destructor virtual?

☆樱花仙子☆ 提交于 2019-12-30 08:08:28
问题 /*Child is inherited from Parent*/ class Parent { public: Parent () //Constructor { cout << "\n Parent constructor called\n" << endl; } protected: ~Parent() //Dtor { cout << "\n Parent destructor called\n" << endl; } }; class Child : public Parent { public: Child () //Ctor { cout << "\nChild constructor called\n" << endl; } ~Child() //dtor { cout << "\nChild destructor called\n" << endl; } }; int main () { Parent * p2 = new Child; delete p2; return 0; } If I make Parent 's destructor virtual,

Is there a use for making a protected destructor virtual?

只愿长相守 提交于 2019-12-30 08:08:05
问题 /*Child is inherited from Parent*/ class Parent { public: Parent () //Constructor { cout << "\n Parent constructor called\n" << endl; } protected: ~Parent() //Dtor { cout << "\n Parent destructor called\n" << endl; } }; class Child : public Parent { public: Child () //Ctor { cout << "\nChild constructor called\n" << endl; } ~Child() //dtor { cout << "\nChild destructor called\n" << endl; } }; int main () { Parent * p2 = new Child; delete p2; return 0; } If I make Parent 's destructor virtual,

Virtual Default Destructors in C++

此生再无相见时 提交于 2019-12-29 17:46:05
问题 I've got a large set of inherited classes (criteria) which inherit from a base class (criterion). Here's criterion 's code class criterion { public: virtual unsigned __int32 getPriorityClass() const = 0; virtual BOOL include(fileData &file) const = 0; virtual void reorderTree() = 0; virtual unsigned int directoryCheck(const std::wstring& directory) const = 0; virtual std::wstring debugTree() const = 0; }; Some examples of derived classes from this one: class fastFilter : public criterion {

Virtual Default Destructors in C++

不打扰是莪最后的温柔 提交于 2019-12-29 17:45:04
问题 I've got a large set of inherited classes (criteria) which inherit from a base class (criterion). Here's criterion 's code class criterion { public: virtual unsigned __int32 getPriorityClass() const = 0; virtual BOOL include(fileData &file) const = 0; virtual void reorderTree() = 0; virtual unsigned int directoryCheck(const std::wstring& directory) const = 0; virtual std::wstring debugTree() const = 0; }; Some examples of derived classes from this one: class fastFilter : public criterion {

virtual desctructor on pure abstract base class

一笑奈何 提交于 2019-12-29 07:33:39
问题 I have struct IMyInterface { virtual method1() = 0; virtual method2() = 0; }; GCC insists that I have struct IMyInterface { virtual method1() = 0; virtual method2() = 0; virtual ~IMyInterface(){}; }; I dont see why. A pure interface is all about the interface (duh). The destructor is part of the internal implementation details of a concrete implementer of the interface; it does not form part of the interface. I understand the whole slicing issue (or at least I think I do) So my question is -

Why virtual destructor?

时光毁灭记忆、已成空白 提交于 2019-12-24 11:36:33
问题 I am going through some code,plan to adapt it for my research.So header file looks like this #ifndef SPECTRALCLUSTERING_H_ #define SPECTRALCLUSTERING_H_ #include <vector> #include <eigen3/Eigen/Core> class SpectralClustering { public: SpectralClustering(Eigen::MatrixXd& data, int numDims); virtual ~SpectralClustering(); std::vector<std::vector<int> > clusterRotate(); std::vector<std::vector<int> > clusterKmeans(int numClusters); int getNumClusters(); protected: int mNumDims; Eigen::MatrixXd

C++ Virtual Destructors in a 4 level inheritance chain.

社会主义新天地 提交于 2019-12-23 20:24:47
问题 I was doing a little experiment with virtual destructors to review - wondering if anyone has a simple explanation for the following (using vs 2010): I Define class hierarchy A-B-C-D, D inherits C, C inherits B, B inherits A, A is the Base; ran 2 experiments: First experiment - A has a virtual Destructor. B has a non-Virtual Destructor C has a virtual Destructor D has a non virtual Destructor //---------------------------- Allocate 4 objects on the heap of type D - Point a pointer of A*, B*

C++ is Virtual destructor still needed if there are no data members in derived?

谁说胖子不能爱 提交于 2019-12-23 07:33:34
问题 Suppose I have this code class Base{ public: int getVal(); private: int a, b; }; class Derived::public Base{ public: void printVal(); }; int main(){ Base *b = new Derived(); delete b; } I know a virtual destructor would delete things properly, but is it bad to delete with base pointer (when there is no virtual destructor) even if there are no virtual functions and no data members in the derived class? What will happen if this is done? 回答1: For primitive-type data, your example will most

Valgrind shows memory leak in std::make_unique

我的未来我决定 提交于 2019-12-23 06:48:10
问题 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}{ }