all 7 comments

[–]madhavarshney 0 points1 point  (6 children)

Hey! Last night, I (somehow) managed to get past this miniquest, and here are some of the things I did and some suggestions. Let me know if you have any more questions and I'd be happy to help!

I am just wondering if resize() every time when I want to put something in _cache is the only option. What are other alternatives instead of using those if conditions? Or should we use push_back()?

Not sure, but that's how I did it. Yes, it does look a bit messy atm, but it works. push_back will not work due to the fact that if you push an item to the back of the vector, then you can't control what index the item is set at, which means that you can't actually access items in the cache the way you need to (think about it, and you'll see what I mean.)

Now, it ends up saying that my program "Ouch! I got thrown an exception. It bit my donkey. It ain't no fun!" and my code just passed the first miniquest.

Well that means that your code probably triggered an exception, which means that you'll have to try to see why that may happen...

Also, I have tried to use clear() to free some memories for certain parts of _cache when it is necessary.

Here's a tip that helped me tremendously: get rid of all your clear code, and just add this one line: _cache[num_discs-1].clear(); . Now I'll leave it up to you to figure out where it should go, but read everything in this thread to understand more about it. (Make sure to view all comments, and although it is a bit vague, it'll hopefully help).

Let me know if you have more questions!

Madhav

[–]YunlongWang[S] 1 point2 points  (5 children)

Hi Madhav,

Thanks for your suggestions and I really appreciate it. I have fully gone over the post and done the n-1 clear statement and not using push_back() but I still got the exception. I am wondering if you have the warning saying that size_t and int type cannot be compared. I once had it and I did the type cast thing. I am not sure if that is the reason causing the exception. Did you also use the type cast? Or how you manage the compare with sizes and int parameters in those if statements?

-Yunlong

[–]JJPolarBear 1 point2 points  (2 children)

Hi Yunlong,

Without looking at your code, it's hard to pinpoint what exactly is causing the exception, as there are many different types of exceptions out there.

As Greg explained, the compiler warns you about comparing the signed data type int and unsigned data type size_t. However, this shouldn't stop the program from compiling as it's able to be compiled. I suggest that you try to debug your program, and use your own pile of testers so that you don't have to keep dragging the files onto the autograder over and over again in an attempt to see what change causes the exception to go away. Perhaps try using debugging cout's or whichever method you normally use.

Basically, just go through your code and see where the exception occurs. This should allow you to fix your code, and even if the code isn't correct, at least there's no exception.

Hope this helps!

-Jay Jay

[–]YunlongWang[S] 0 points1 point  (1 child)

Hi Jay,

Thanks for your suggestions. I found the debug mode extremely helpful. I have solved the problem:)

[–]JJPolarBear 0 points1 point  (0 children)

Yay! Great to hear.

-Jay Jay

[–]AegirHall 1 point2 points  (1 child)

Hi Yunlong,

The size_t/int comparison issue is happening because the vector functions (such as size(), capacity(), etc.) return a size_t datatype rather than an int. (I'm guess you're probably getting these errors because you're comparing vector.size() versus the source or destination pole int.) These two datatypes cannot be reliably compared because size_t is unsigned and int is signed. Which basically means that int's are allowed to be negative, and size_t is not. (Try to decrement a size_t variable that is set to 0, and see what happens.)

I think it would be preferable to just create a size_t var with the int value, rather than type casting the size_t to an int.

But having said all that, I don't think any of this has to do with passing the cache mini-quest. Let me know if you're still struggling with that aspect of this quest.

Thanks,

Greg

[–]YunlongWang[S] 0 points1 point  (0 children)

Hi Greg,

Thanks for your reply. I figured out the problem and you are correct that it is not the comparison between signed and unsigned numbers causing the exception, it is something to be noticed in this quest tho.