virtual-destructor Questions
2
Solved
There is already a question asking about the "real-world" behavior of deleteing a pointer to a base class that lacks a virtual destructor, but the question is restricted to a very limited case (the...
Therefore asked 21/8, 2015 at 3:47
12
Solved
Is there ever a good reason to not declare a virtual destructor for a class? When should you specifically avoid writing one?
Petry asked 19/11, 2008 at 4:27
1
Solved
When adding a user defined default virtual destructor to a class like this..
class Foo
{
public:
Foo();
virtual ~Foo() = default;
};
.. It has the side effects of preventing auto generation of...
Isidor asked 1/2, 2016 at 10:0
3
Solved
Why are all destructors, ~D(),~C(),~B(),~A() being called in the example below?
There is only one virtual destructor: that of A.
Here is the code:
#include<iostream>
using namespace std;
...
Terryl asked 17/10, 2012 at 5:31
3
Solved
Classes with non-virtual destructors are a source for bugs if they are used as a base class (if a pointer or reference to the base class is used to refer to an instance of a child class).
With the...
Artiodactyl asked 6/6, 2015 at 17:27
4
Solved
When we go out of catch block scope, does the exception destructor get called?
(In case we don't rethrow it)
Suppose I have class A, and that its destructor is not virtual.
B inherits A.
Suppose s...
Timmie asked 5/2, 2015 at 20:48
4
In the code below, why is the ~Derived() destructor called automatically?
#include<iostream>
using namespace std;
class Base
{
public:
virtual ~Base()
{
cout << "Calling ~Base()" &l...
Remodel asked 24/10, 2014 at 12:15
2
Solved
In C++ I am aware that a virtual destructor should generally be used when one intends to inherit from a base class. However, with C# I am not sure what should be done. Consider the following code:
...
Waylen asked 9/5, 2014 at 23:9
2
Solved
Consider this example :
#include <cstdio>
#include <memory>
struct base
{
base( int i ): i(i) { printf("base ctor\n"); }
~base() { printf("base non-virtual dtor\n"); } // non-virtua...
Inky asked 2/3, 2014 at 7:21
1
I find The rule of Zero as also mentioned on Peter Sommerlads Slides (p.32) very compelling.
Although, I seem to remember that there was a strict rule that one has to define the destructor virtual,...
Married asked 7/2, 2014 at 20:33
2
#include<iostream>
class base
{
public:
virtual ~base(){std::cout << "base\n";}
};
class derived : public base
{
private:
~derived(){std::cout << "derived\n";} /* destructor ...
Supererogation asked 18/11, 2013 at 4:14
3
Solved
I ran into a heap corruption today caused by different CRT settings (MTd MDd) in my dll and my actual project.
What I found strange is that the application only crashed when I set the destructor in...
Forrest asked 8/7, 2013 at 16:28
1
class Base
{
public:
Base(){Foo();}
~Base(){Foo();}
virtual void Foo(){std::cout<<"base";}
};
class Derived: public Base
{
public:
Derived(){Foo();}
~Derived(){Foo();}
voi...
Bigeye asked 2/9, 2013 at 21:8
2
Solved
If I define a class like this:
class A{
public:
A(){}
virtual ~A(){}
virtual void func(){}
};
Does it mean that that the virtual destructor and func are inlined
Eulaliaeulaliah asked 25/8, 2013 at 18:4
3
Solved
I'm not quite sure I understand virtual destructors and the concept of allocating space on the heap right. Let's look at the following example:
class Base
{
public:
int a;
};
class Derived : pub...
Montalvo asked 4/8, 2013 at 20:6
2
Solved
Does the override identifier after virtual destructor declaration have any special meaning?
class Base
{
public:
virtual ~Base()
{}
virtual int Method() const
{}
};
class Derived : public Ba...
Ironclad asked 29/7, 2013 at 11:56
2
Solved
BaseClass * p = new DerivedClass();
delete p;
I know the 2nd line will call the destructor of the base class if it doesn't have a virtual destructor and that of the derived class if it does...
Hovey asked 11/5, 2013 at 14:47
3
Solved
Consider
class A
{
public:
virtual void foo () = 0;
};
At this point it is absolutely obvious that A is an abstract class and will never be instantiated on it's own. So why the standard doesn't...
Crankshaft asked 14/11, 2012 at 18:46
7
Solved
I know it is a good practice to declare virtual destructors for base classes in C++, but is it always important to declare virtual destructors even for abstract classes that function as interfaces?...
Pegeen asked 7/11, 2008 at 0:55
2
Solved
I've had some second thoughts on multiple virtual destructors, esp. after reading reading http://blogs.msdn.com/b/oldnewthing/archive/2004/05/07/127826.aspx .
Suppose I have
class Base
{
publ...
Pithy asked 17/11, 2012 at 0:25
3
Solved
I'm starting to learn c++ but I'm stuck in the destructor. We need to implement a vector and this is what I have so far.
#include<string.h>
#include<cassert>
#include<iostream>
...
Behistun asked 26/10, 2012 at 12:2
6
Solved
Do we need a virtual destructor if my classes do not allocate any memory dynamically ?
e.g.
class A
{
private:
int a;
int b;
public:
A();
~A();
};
class B: public A
{
private:
int c;
...
Orestes asked 14/1, 2010 at 17:2
4
Solved
I have two classes:
class A {
public:
virtual void somefunction() = 0;
};
class B : public A {
public:
B();
~B();
void somefunction();
};
B::B() {}
void B::somefunction() {
// some code
}
...
Trudietrudnak asked 29/4, 2011 at 4:5
5
Solved
As I know, any class that is designated to have subclasses should be declared with virtual destructor, so class instances can be destroyed properly when accessing them through pointers.
But why i...
Demurrage asked 2/1, 2012 at 5:59
4
Solved
This question is different than 'When/why should I use a virtual destructor?'.
struct B {
virtual void foo ();
~B() {} // <--- not virtual
};
struct D : B {
virtual void foo ();
~D() {}
};
...
Tollhouse asked 22/12, 2011 at 3:46
© 2022 - 2024 — McMap. All rights reserved.