0
Int size;  //size is variable
cout<<"enter size";
cin>>size;
Inventory p[size];
/*Inventory is a class.p is an 
 object of inventory class.*/

I want to implement array object with size variable but I'm getting error "expression mush have a constant value"

  • This is correct. In `c++` the size of an array must be a compile time constant. The proper solution in `c++` is to use a `std::vector` for your dynamically sized array. – drescherjm Jun 04 '21 at 03:37
  • 1
    You try to define a [variable-length array](https://en.wikipedia.org/wiki/Variable-length_array). Those aren't part of the C++ language. Use `std::vector` instead. – Some programmer dude Jun 04 '21 at 03:38

0 Answers0