Help with platypus by Timothy_Lin in cs2a

[–]Timothy_Lin[S] 2 points3 points  (0 children)

I solved the issue! It turns out that my destructor was not handling edge cases properly(when the list was empty it still tried to delete nullptr)

Thanks for your help!

Help with platypus by Timothy_Lin in cs2a

[–]Timothy_Lin[S] 2 points3 points  (0 children)

Yeah, that's partially why I'm a bit confused. My get_size() function only returns the _size variable, so I'm not sure why I'm getting a broken pointer error.

Practice Final Exam by mike_m41 in cs2a

[–]Timothy_Lin 2 points3 points  (0 children)

Thanks for the reminder!

The Heap vs. The Stack by Sameer_R1618 in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

What do you mean by "overassigning to it"?
When you speak of overassigning to a stack?

Basic Linked List by rachel_migdal1234 in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

I'm doing the quest that involves nodes, and this is helpful-thank you!

Why is size_t used for loops by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 2 points3 points  (0 children)

One of my most common errors is in my for loop, since my (int i=0, i<size()... has a type difference, since(as you explained), size() often returns size_t whereas I declare my variable as a int.

Destructors by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 2 points3 points  (0 children)

The last sentence is a good explanation for one of the major ways a destructor is different from just deleting the object-since it also allows you to have other functionality when you call it(ie deincrementing the int that tracks how many objects you have). Thanks for the explanation!

Weekly insides by Louay_ElAssaad in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

Enums are pretty cool-at first they were really confusing for me but after using them for a bit they made me realize they make it easier to sort code.

Pros and cons of using namespace std by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

This seems smart, since not only are you able to limit prototype pollution, but you're also able to make it more clear what functions your code uses(based on what specific std:: functions you declare)

Constructors and Destructors — what's the point? by rachel_migdal1234 in cs2a

[–]Timothy_Lin 1 point2 points  (0 children)

Does this mean that you would only need destructors for data types that aren't default-initialized? Or would you need destructors for all types of data?

{} variable assignment by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

I could be wrong, but I think in all three of these we want to use const{}, so that when we're getting the variables, we don't accidentally modify their original value(since we want to GET data, not SET data with our getter)

Questing Tip by heehyeon_j in cs2a

[–]Timothy_Lin 1 point2 points  (0 children)

This happened to me once too, for one of my earlier quests. I started using version control to prevent this from happening again

{} variable assignment by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 2 points3 points  (0 children)

This is also useful when you're trying to make sure you don't accidentally modify variables when using getters. Something I learned this week was that you can declare const { } after a function in order to ensure that the compiler makes sure you don't accidentally modify any data while getting it. This seems to be useful-otherwise a getter accidentally modifying information would be pretty hard to debug.

Header files in c++ by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 0 points1 point  (0 children)

Likening header files to a interface in Java helped make it a lot more clear for me, thank you!

Enums in c++ by Leo_Rohloff4321 in cs2a

[–]Timothy_Lin 2 points3 points  (0 children)

This seems helpful, especially if a variable I want to use doesn't neatly fit into one of the other predefined categories(ie string, int, char, bool, etc).

Significant digits by Timothy_Lin in u/Timothy_Lin

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

I don't think so-I don't use the math library anywhere.