virtual-destructor Questions

3

Solved

I have this code: class Class { public: virtual ~Class() {} }; int main() { Class* object = new Class(); delete object; } which I compile with Visual C++ 10 and get this disassembly for dele...
Cookery asked 8/11, 2011 at 14:43

1

Solved

I found this code on a web site #include <iostream> using namespace std; struct Base { Base() { cout << "Base" << " "; } virtual ~Base() { cout << "~Base" << endl...

1

Solved

I've just updated GCC from (I think) 4.5.6 to 4.6.1, under Windows, MinGW. Suddenly my NonInstantiable base class (from which you inherit with public virtual to prevent instantiation) refuses to wo...
Albric asked 28/9, 2011 at 17:28

5

Solved

This example below illustrates how to prevent derived class from being copied. It's based on a base class where both the copy constructor and copy assignment operator are declared private. class U...
Puissance asked 10/8, 2011 at 1:56

1

Solved

Since boost::/std::shared_ptr have the advantage of type-erasing their deleter, you can do nice things like #include <memory> typedef std::shared_ptr<void> gc_ptr; int main(){ gc_pt...
Kikelia asked 9/7, 2011 at 12:28

3

Solved

Why doesn't C++ make destructors virtual by default for classes that have at least one other virtual function? In this case adding a virtual destructor costs me nothing, and not having one is (almo...
Ehrsam asked 8/7, 2011 at 1:31

2

Solved

I tried the following code on gcc 4.4.5. If the member 'data' is not present, the code executes fine, but in its presence, it crashes. It also doesn't crash when the derived class' dtor is not vir...
Jessamyn asked 27/5, 2011 at 16:41

3

In this answer, Ryan directly calls the virtual destructor. I've tested the code in VS2010, and it correctly calls all destructors (tested with logging statements). Is it actually valid to do so? W...
Cymophane asked 17/5, 2011 at 19:30

3

Solved

I've got a scenario where I'm writing somewhat deep object oriented code, with multiple layers of abstract base classes, and I'm wondering if I have to explicitly declare a destructor for each one....
Gravois asked 10/4, 2011 at 6:22

3

Solved

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; }...
Animatism asked 15/10, 2010 at 18:0

4

Solved

I didn't see the answer to this in the C++ Faq lite: How do I define a base class so every class inheriting it is required to define a destructor? I tried running this program struct VDtor { vir...
Polyhymnia asked 13/9, 2010 at 12:44

8

Solved

Can some one please help what the order of destruction is when I am using virtual functions. Does it start with the base class and then derived class?
Percolation asked 17/8, 2010 at 21:29

2

Solved

I have struct IMyInterface { virtual method1() = 0; virtual method2() = 0; }; GCC insists that I have struct IMyInterface { virtual method1() = 0; virtual method2() = 0; virtual ~IMyInterf...
Mcnew asked 26/7, 2010 at 15:46

3

Solved

This has probably been asked before on SO, but I was unable to find a similar question. Consider the following class hierarchy: class BritneySpears { public: virtual ~BritneySpears(); };...
Differentia asked 2/7, 2010 at 15:24

7

Solved

Java and C# support the notion of classes that can't be used as base classes with the final and sealed keywords. In C++ however there is no good way to prevent a class from being derived from which...
Cass asked 9/12, 2008 at 18:56

6

Solved

Possible Duplicate: When to use virtual destructors? When should your C++ object's destructor be virtual?
Solley asked 14/7, 2009 at 1:37

4

Solved

If we define a abstract class which has a pure virtual destructor, why do we have to give a definition of a destructor in the abstract class?
Calvinna asked 16/6, 2009 at 2:27

4

Solved

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() con...
Traipse asked 5/5, 2009 at 22:28

© 2022 - 2024 — McMap. All rights reserved.