0

I'm making a singly Linked List called Tracks, why is it throwing exception when I try to make a ptr of type Tracks and assign head to it. It also gives same error when I assign mbidd value to node->trackRef->mbid

Test Case:

TEST(SoundCloudTesting, AlbumDatabase) { string path = "Albums.csv"; ad = Create_AD<int, string, float>(path); //function to be implemented int expected_albums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; //expected abid(s) //Testing AD Data structure AD<int, string, float>* current = ad; for (int i = 0; i < 13; i++) { EXPECT_EQ(expected_albums[i], current->abid); current = current->next; } EXPECT_EQ(1, current->abid); } 

Please check the error

4
  • Please post a minimal reproducible example, not just the class, but also a main that duplicates the error. Commented Apr 30, 2021 at 2:57
  • Where is your source code that uses this class? (Your input which caused the crash) Commented Apr 30, 2021 at 3:04
  • What's the definition of MMD? Commented Apr 30, 2021 at 3:04
  • Updated the code. Commented Apr 30, 2021 at 3:17

1 Answer 1

1

The member variable trackRef is a pointer and was never initialized, but you dereferenced it here:

trackRef->mbid = 0; 

I can't tell from your code where trackRef is meant to be created for each new Tracks or should be passed in to the constructor, but at the moment there is no code that sets it to anything before it is used.

Sign up to request clarification or add additional context in comments.

5 Comments

It is still throwing exception when I assign mbidd value to node->trackRef->mbid
With your updated code you set trackRef to nullptr then try to dereference it createList - if you want to dereference a pointer it must point to valid memory.
But I want my linked list empty at first, how should I point it to a valid memory?
What is trackRef meant to be for? What does it hold? It seems to be another linked list of MMD objects, but why is it a linked list? What is in charge of this other linked list? Is there one MMD linked list per Tracks object, or do they all somehow share that linked list?
One node of AD (Album Database) should have a linked list of Tracks in which songs of that particular Album are listed on the basis of MBID (Music Database ID). MMD linked list have all the songs stored.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.