Catalogint maxProducts if maxProducts 1 throw invalidargu

Catalog(int maxProducts)

{

if (maxProducts < 1)

{

throw invalid_argument(\"Cannot create catalog with less than 1 product.\");

}

mP = maxProducts;

_list = new Product[mP];

}

trying to call

Catalog a(20*1000*1000);

from main but wont work because its too big for stack.. how do i fix this code

Solution

There is a minor mistake in the function that you are calling. I can see that you are calling like \"Catalog a(20*1000*1000)\" where you should actually call like \"Catalog(10*2000*2000)\" and the other mistake that seems here is in the argument of the function definition you are using int maxProducts instead prefer to use long maxProducts,

Catalog(int maxProducts) { if (maxProducts < 1) { throw invalid_argument(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site