Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 651573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:10:36+00:00 2026-05-13T22:10:36+00:00

I have a cd , dvd. book media program. Currently, i am trying to

  • 0

I have a cd , dvd. book media program. Currently, i am trying to add book information to a set. I am getting a nasty crash.

error: Unhandled exception at 0x00449d76 in a04xc.exe: 0xC0000005: Access violation reading location 0x00000014.

So, obviously its trying to access memory its not suppose to? just not sure why or what i need to do to add information?

Its coming from this line in this function…

const Item* Library::addBook(const string& title, const string& author, const int nPages)
{

Book* item = new Book(title,author,nPages);
allBooks.insert(item); // add to set of all books
allBooksByAuthor[author]->insert(item);  // causing error..
return item;

}

here is the driver..

// add items to library
cout << ">>> adding items to library:\n\n";
item = library->addBook("The Curious Incident of the Dog in the Night-Time", "Mark Haddon", 240);
if (item != NULL) {
    library->addKeywordForItem(item, "autism");
    library->addKeywordForItem(item, "Asperger's Syndrome");
    library->printItem(cout, item);
    }

here is part of the library cpp where i am having problems with addbooks function

#include "Library.h"
#include "book.h"



ItemSet allBooks;                // for my sets defined in the Items cpp
ItemSetMap allBooksByAuthor;


void Library::addKeywordForItem(const Item* item, const string& keyword)
{

//item->addKeyword(keyword);

}

const ItemSet* Library::itemsForKeyword(const string& keyword) const
{
return NULL;
}

void Library::printItem(ostream& out, const Item* const item) const
{
}

// book-related functions

const Item* Library::addBook(const string& title, const string& author, const int nPages)
{

Book* item = new Book(title,author,nPages);
allBooks.insert(item); // add to set of all books
allBooksByAuthor[author]->insert(item);  // add to set of books by this author
return item;

}

here is the items class

#pragma once

#include <ostream>
#include <map>
#include <set>
#include <string>
#include "Item.h"

using namespace std;

typedef set<Item*>              ItemSet;
typedef map<string,Item*>       ItemMap;
typedef map<string,ItemSet*>    ItemSetMap;

class Library
{

public:
// general functions

void addKeywordForItem(const Item* const item, const string& keyword);
const ItemSet* itemsForKeyword(const string& keyword) const;
void printItem(ostream& out, const Item* const item) const;

// book-related functions

const Item* addBook(const string& title, const string& author, int const nPages);
const ItemSet* booksByAuthor(const string& author) const;
const ItemSet* books() const;

// music-related functions

const Item* addMusicCD(const string& title, const string& band, const int nSongs);
void addBandMember(const Item* const musicCD, const string& member);
const ItemSet* musicByBand(const string& band) const;
const ItemSet* musicByMusician(const string& musician) const;
const ItemSet* musicCDs() const;

// movie-related functions

const Item* addMovieDVD(const string& title, const string& director, const int nScenes);
void addCastMember(const Item* const movie, const string& member);
const ItemSet* moviesByDirector(const string& director) const;
const ItemSet* moviesByActor(const string& actor) const;
const ItemSet* movies() const;
};

here is book.h

#ifndef BOOK_H
#define BOOK_H

#pragma once
#include "item.h"

using namespace std;

class Book : public Item
{
public:
Book(const string& title, const string& author, const int nPages);
~Book();
const int getPages() const;
const string getAuthor() const;
virtual void print(ostream& out) const;

private:

int numPages;
string Author;

};
ostream& operator<<(ostream& out, const Book* book);
#endif

I am just learning STL and i am having a hard time learning whats going on here.
i understand set. I am just not sure in my situation map is for? is it adding item to author? and them adding them both to ItemSetMap?

typedef set<Item*>                ItemSet;
typedef map<string,Item*>         ItemMap;
typedef map<string,ItemSet*>      ItemSetMap;

so, how can i fix this crash? am i not adding author to item correctly?

Thank You..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:10:36+00:00Added an answer on May 13, 2026 at 10:10 pm

    The correct answer is to change the map to contain set objects, rather than pointers, as JonM says.

    However, if you are constrained to store pointers, then you will need to manually create a new set when it’s needed. For a new author, using allBooksByAuthor[author] will insert a new entry with a null pointer, which you mustn’t dereference. In that case, you’ll need to create a new set and update the pointer in the map. You could also look at allBooksByAuthor.find(author), which has different behaviour for a new author.

    You’ll then need to make sure that the sets are deleted when they are removed from the map, and any remaining ones are deleted when the map is deleted, otherwise the memory allocated for them will be lost for ever. This kind of resource leak is one reason why you should never deal with raw pointers like this; storing objects in the map would completely take care of memory management for you.

    Since this is homework, I won’t give you any code – this should be enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have just started using Google Chrome , and noticed in parts of our site,
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have had to write my first proper multithreaded coded recently, and realised just how
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.