well this is my code. i need to create a vector of pointers and hold the book objects in it. then i have a virtual function in my books which is a pure virtual in LibraryItems.when i try to add the books object in my code, i understand that since the scope runs out there is no object that is added. so when i run print it gives me an error. cant figure out
You should create your objects in heap instead of stack.
Note that you will run into memory leak issue or ugly manual management with vector of raw pointers.
Use unique_ptr instead (or shared_ptr if you need an shared ownership)