virtual-destructor Questions
21
Solved
I have a solid understanding of most OOP theory but the one thing that confuses me a lot is virtual destructors.
I thought that the destructor always gets called no matter what and for every object...
Oldfangled asked 20/1, 2009 at 12:58
4
What is the correct way to declare instantiation methods when defining an interface class?
Abstract base classes are required to have a virtual destructor for obvious reasons. However, the followi...
Protector asked 22/4, 2018 at 1:49
5
I am pretty sure this question is duplicate, but my code is different here, the following is my code. It fails with a "Undefined symbols" error, not sure whats missing.
class Parent {
public :
v...
Endermic asked 6/8, 2015 at 17:9
4
Solved
#include <iostream>
using namespace std;
class base
{
int a;
public:
base() {a =0;}
};
class derv :public base
{
int b;
public:
derv() {b =1;}
};
int main()
{
base *pb = new der...
Extraterritorial asked 6/1, 2012 at 0:58
1
Solved
The following class (with virtual destructor) contains a templated operator delete:
struct S
{
virtual ~S() {}
template <typename... Args>
void operator delete(void* ptr, Args... args);
};...
Ulane asked 11/8, 2022 at 14:34
5
Solved
I want to inherit from std::map, but as far as I know std::map hasn't any virtual destructor.
Is it therefore possible to call std::map's destructor explicitly in my destructor to ensure proper o...
Shiksa asked 7/5, 2012 at 6:47
4
Solved
I am trying to understand virtual destructors. The following is a copy paste from this page When to use virtual destructors?
Here, you'll notice that I didn't declare Base's destructor to be
vi...
Pimentel asked 25/10, 2013 at 1:8
5
Solved
/*Child is inherited from Parent*/
class Parent {
public:
Parent () //Constructor
{
cout << "\n Parent constructor called\n" << endl;
}
protected:
~Parent() //Dtor
{
cout <...
Lampoon asked 23/1, 2012 at 10:51
10
Solved
Due to the well-known issues with calling virtual methods from inside constructors and destructors, I commonly end up with classes that need a final-setup method to be called just after their const...
Peculiarize asked 20/7, 2009 at 5:7
2
Solved
In a freestanding context (no standard libraries, e.g. in operating system development) using g++ the following phenomenon occurs:
class Base {
public:
virtual ~Base() {}
};
class Derived : publ...
Glottochronology asked 28/7, 2015 at 20:32
4
Solved
I know the cases where pure virtual destructors are needed. I also know that If we don't provide an implementation for them it will give me a linker error. What I don't understand is why this shoul...
Retha asked 14/1, 2014 at 9:0
4
Solved
In these slides about C++11/14 standard, on slide 15, the author writes that "many classic coding rules [are] no longer applicable" in C++11. He proposes a list of three examples, and I agree with ...
Assentation asked 2/4, 2014 at 9:6
5
Solved
If I have a base class with a virtual destructor. Has a derived class to declare a virtual destructor too?
class base {
public:
virtual ~base () {}
};
class derived : base {
public:
virtual ~de...
Autoclave asked 4/2, 2010 at 9:0
2
While thinking about this question, I stumbled upon something else I don't understand.
Standard says...
[class.dtor]/4
If a class has no user-declared destructor, a destructor is implicitl...
Tetramethyldiarsine asked 24/10, 2019 at 14:10
7
Solved
Based on what I found here and on other links on stackoverflow, we should always define a virtual destructor in the base class if we plan to use it polymorphically. I want to know if there is...
Wordy asked 30/7, 2019 at 15:48
2
Solved
Inspired by the post Why does destructor disable generation of implicit move methods?, I was wondering if the same is true for the default virtual destructor, e.g.
class WidgetBase // Base class o...
Extort asked 27/11, 2015 at 12:4
2
Solved
In the following simple code fragment:
#include <cstddef>
struct B
{
virtual ~B() = default;
static void operator delete(void *, int);
static void * operator new(size_t, int);
};
struct...
Boracic asked 10/11, 2015 at 8:54
1
Solved
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>
#...
Stiffler asked 5/9, 2018 at 8:24
3
Solved
I have a base class A with a virtual destructor. A has descendants B and C which use the default destructor. Is it safe to delete an object of C through a pointer to A?
More specifically, consider...
Flat asked 20/1, 2018 at 12:43
3
Solved
We know that if there are virtual functions then the base class destructor should be marked as virtual as well, otherwise it is undefined behavior when explicitly deleted with base class pointer if...
Lei asked 12/10, 2014 at 2:21
4
Solved
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,...
Transitory asked 15/6, 2012 at 16:56
1
Solved
In following example, b is a polymorphic pointer type whose static type is Base* and whose dynamic type is Derived*.
struct Base
{
virtual void f();
};
struct Derived : Base
{
};
int main()...
Personalism asked 22/9, 2016 at 7:14
7
I came across a base class whose destructor is non-virtual, although the base class have 1 virtual function fv(). This base class also has many subclasses. Many of those subclasses define its own f...
Vitrification asked 22/8, 2016 at 7:48
1
Solved
I've created a header for optionally-lazy parameters (also visible in a GitHub repository). (This is not my first question based on the header.)
I have a base-class template and two derived-class ...
Hurtle asked 5/7, 2016 at 23:0
3
Solved
UPD. There is a mark that it is a duplicate of this question. But in that question OP asks HOW to use default to define pure virtual destructor. This question is about what the difference.
In C++ ...
Pachston asked 12/6, 2016 at 18:19
1 Next >
© 2022 - 2024 — McMap. All rights reserved.