I'm having problems with an assert in MSVC++, and a custom Vector Class
using a virtual Destructor.
The Template Class Constructor looks as follows:
// vector.h
template <class Object>
class vector {
public:
// Using Default ctor, we clearly malloc for Object[0]
vector( int theSize = 0 ) : currentSize( theSize )
{ objects = new Object[ currentSize ]; }
// virtual and non virtual does not matter
virtual ~vector( ) { delete [ ] objects; }
// ... Other Members
}
If the driver looks as follows, all is OK (no VC++ Assert):
int main( ) {
vector<int> f;
f.resize( 20 );
return 0;
}
If the driver looks as follows, VC++ Asserts:
class Foo {
public:
Foo( ) { }
virtual ~Foo( ) { }
};
int main( ) {
vector<Foo> f;
f.resize( 20 );
return 0;
}
VC++ Language reference says both above examples are valid per
http://msdn.microsoft.com/library/devprods/vs6/visualc/vclang/_pluslang_the_
operator_new_function.htm
ANSI also allows this (see
http://www.cygnus.com/misc/wp/dec96pub/expr.html):
5.3.4.8
When the value of the expression in a direct-new-declarator is zero,
the allocation function is called to allocate an array with no ele-
ments. The pointer returned by the new-expression is non-null and
distinct from the pointer to any other object.
Any Ideas?
Jeff
jwa...@nospam.umbc.edu
ISTR this is a known bug. Use std::vector, which avoids this problem.
--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows
Jeff
==========================================
"Doug Harrison [MVP]" <d...@mvps.org> wrote in message
news:r2morscukd3jnbnl0...@4ax.com...