Microsoft KB Archive/130547

= FIX: C2300 on Explicit Destructor Call in Class Template =

Article ID: 130547

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1

-



This article was previously published under Q130547



SYMPTOMS
A class template that makes an explicit call to destructor through a pointer of the template argument  generates the following error if the class template is instantiated with a class type:

error C2300: 'MyClass' : class does not have a destructor called '~Item'



RESOLUTION
You can work around this problem by using the scope resolution operator when calling the destructor: cpR->Item::~Item; If the pointer points to an object of a derived class, the objects's virtual destructor is not called. In this case, it may be nessary to call another virtual function instead, which then calls the virtual destructor.

Also, this syntax can cause problems if the template is instantiated with a simple type. See the "References" section of this article for more information.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, 32-bit Edition, version 4.0.



Sample Code to Demonstrate Problem
// Compile options needed: none template class classX { public: void funcX; Item* cpR; };

template void classX::funcX { cpR->~Item; };

class MyClass { public: ~MyClass {}; };

