Re: const as array size
On Feb 23, 9:57 am, "Íõ¾ý³¼" <WangJunc...@gmail.com> wrote:
> On 2ÔÂ23ÈÕ, ÏÂÎç11ʱ21·Ö, asit <lipu...@gmail.com>wrote:
>
> > We know that array size can be a constant integer.
>
> > Consider the following case ??
>
> > calss myc
> > {
> > const int size;
> > int arr[size];
> > public:
> > myc(int x):size(x){}
>
> > }
>
> > Why the above code shows an error ??
>
> > How can we overcome it ??
>
> template<int SIZE>
> class myc
> {
> int arr[SIZE];
> //......}
>
> void main()
That's not C++! You might have meant to write
int main()
> {
> myc<6> c1;// arr size wil be 6;
> myc<8> c2;// arr size will be 8;
Not necessarily 6 or 8, unless it's a legal C++ program.
Ali
|