virtual-methods

Virtual methods chaos, how can I find what causes that?

A colleague of mine had a problem with some C++ code today. He was debugging the weird behaviour of an object's virtual method. Whenever the method executed ( under debug, Visual Studio 2005 ), everything went wrong, and the debugger wouldn't step in that method, but in the object's destructor! Also, the virtual table of the object, only...

Visitor and templated virtual methods

In a typical implementation of the Visitor pattern, the class must account for all variations (descendants) of the base class. There are many instances where the same method content in the visitor is applied to the different methods. A templated virtual method would be ideal in this case, but for now, this is not allowed. So, can te...

Virtual methods make the application slower, but can they speed up the linking?

As described in http://stackoverflow.com/questions/449827/virtual-functions-and-performance-c virtual methods may have an impact on performance (extra lookup in vtable, no inlining, ...). But I was wondering, could the use of virtual functions speed up the linking process? Suppose that I have a class X, calling a method of class Y. I...

Why does this virtual destructor trigger an unresolved external?

Consider the following: In X.h: class X { X(); virtual ~X(); }; X.cpp: #include "X.h" X::X() {} Try to build this (I'm using a .dll target to avoid an error on the missing main, and I'm using Visual Studio 2010): Error 1 error LNK2001: unresolved external symbol "private: virtual __thiscall X::~X(void)" (??1X@@EAE@XZ...

How can I ensure that a class has no virtual methods?

I have a class whose objects are used in shared memory. Therefore, I must be sure that they do not have virtual methods (which crash the program when called via vtable). I would like to guard against anybody accidentally adding a virtual method in violation of this requirement. Ideally, the compiler would refuse to even compile the clas...