hi,
i'm trying to design a program for book inventory. i've defined funtions such as getdata(), search() and display() in a class. now i have to create objects in main to access these functions.
normal syntax for creating objects will be:
class_name object_name;
eg-
books s1;
if i write a statement
s1.getdata();
i can access that function but imagine that i want to create n number of objects to access those functions then how can i do it??
i tried
int n;
int i;
books s[i];
cin>>n;
for(i=0;i<n;i++)
{
s[i].getdata();
}
but the error is that i can use only constant expression for size of array. i can give that but i'm also using a constructor to update stock position,
books()
{
stock_pos++
}
so if i create objects as s[100], stock_pos value becomes 100 at the time of execution so it will display stockposition=100 even when i enter details of 1st book and also for all books. can someone help me?