BUG: C2233 on User-Defined Type Array Member of Template Class

ID: Q216977


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 6.0


SYMPTOMS

When compiling a template class that contains a data member that is an array of a second template class, and the second class contains a data member that is an array, and the size of both arrays is dependent on a template parameter, you will receive the following error:

error C2233: '<Unknown>' : arrays of objects containing zero-size arrays are illegal


RESOLUTION

Use a pointer instead of an array. Allocate the space for the array in the constructor and deallocate the space for the array in the destructor.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Behavior


template <int k>
class A
{
    char x[k];
};

template <int h, int j>
class B  
{
     A<h> y[j];
}; 

Workaround


template <int k>
class A
{
    char *x;
    A() {
        x = new char[k];
    }
    ~A() {
        delete[] x;
    }
};
template <int h, int j>
class B  
{
     A<h> y[j];
}; 

Additional query words:

Keywords : kbCompiler kbCPPonly kbVC600bug
Version : winnt:6.0
Platform : winnt
Issue type : kbbug


Last Reviewed: February 19, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.