Help me with C++ project; AHHH

Sort:
Avatar of ChampoftheBepoCamp

I get segmentation fault (core dumped) with the Try Catch... sad.png

void search() {
int logic;
cout << "Type the Year:\n";
cin >> logic;

for (int i = 0; i < storage.size(); i++) {
if (storage[i]->getYear() == logic) {
cout << storage[i]->getTitle() << endl;
/*
try {
cout
<< storage[i]->getPublisher() << endl
<< ((dmovies*)storage[i])->getDirector() << endl
<< ((cmusic*)storage[i])->getArtist() << endl
<< storage[i]->getDuration() << endl
<< storage[i]->getRating()
;
}
catch(int zero) {
zero = 5;
}
*/
cout << storage[i]->getYear() << endl;
}
}
Avatar of the_fire_bird

what

Avatar of KyloAPPROVES

Its coding language

Avatar of KyloAPPROVES

Probably. I only know some JavaScript.

Avatar of llama47

With which functions?

Test them individually, and if one doesn't work (like getYear) then you'd have to show us that code.

It's been a while since I did C++. As I recall & and * undo each other right? Like & is the address, and * is the pointer... so can you use * the way you're using it? If you're trying to access some random piece of memory that's what causes a core dump right?

But yeah, like I said, it's been a few years.

Avatar of llama47

In general, write as little as possible before you stop and test things. It will feel slow at first, but it makes the process a lot easier.

Avatar of ChampoftheBepoCamp

Update: I got the error fixed on the delete function, I am using the vector for searching and adding also and I have a global int that tracks the size of the vector and I add that each time I add something, so I needed to add --storageTracker;  in the delete function ;

Avatar of ChampoftheBepoCamp

When I am searching for functions I try to match the year that you search with any year of the 3 child; video games, music and movies, then it mathes I want to print the entire thing. But the problem is I can't just do that, since I have certain getters on the child only like music has artist, so I dump the functions that aren't in parent in the try catch and well that causes errors.

Avatar of llama47

Ah yeah, certain classes don't have access to each other, the parent child / public private stuff, it's been a while since I've messed with that.

Avatar of ChampoftheBepoCamp

yea & is for reference while * is for pointers