I am trying to make a library, where the user initializes multiple books(Object bookType), and their names are saved into a dynamic array called books[1]. i was trying to use pointers to expand the array's size each time a new book is defined.
while running my compiler breaks and gives me an error that "memory access violation" , i do realize that the mistake is because a string doesnt have a consistent size. So how can i know what size each of the names occupies in memory so that i can move that number of locations in memory ????
my code is :
// pb is pointer of books
//NOfB is number of books
Expand|Select|Wrap|Line Numbers
- void bookType::setName(string n)
- { name = n;
- cout << n;
- system("pause");
- *(pb+NOfB)= n;
- NOfB++;
- system("pause");
- }