const as array size

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asit

    const as array size

    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 ??
  • Kyle

    #2
    Re: const as array size

    asit napisał(a):
    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 ??
    because array size needs to be a compile time constant integer
    >
    How can we overcome it ??
    by using std::vector<int >

    Comment

    Working...