Discussion: const as array size
Afficher un message
Vieux 23/02/2008, 20h07   #5
acehreli@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
 
Page generated in 0,05222 seconds with 9 queries