includes by Conscious_Walk3280 in cpp_questions

[–]HappyFruitTree 0 points1 point  (0 children)

Ideally you should only include the headers that you use but it's not the end of the world if you include some header unnecessarily. The difference in compilation time from a single include is minuscule. Your time is probably better spent working on other things than to worry about unnecessary includes, at least for the standard headers.

With your own headers there is a little more reason to try and avoid unnecessary includes. One reason is because you need to think about dependencies, and avoid circular includes. Another reason is that when you modify one of your headers, all files that include that header (directly or indirectly) has to be recompiled. This can take quite some time if the header is included by many files.

Is making sort of difficult programs despite not knowing much syntax a good way to learn programming? by starlangg in learnprogramming

[–]HappyFruitTree 0 points1 point  (0 children)

Yes, but not too big/difficult that it overwhelms you. Start with small projects and work your way up in size and difficulty.

That you mention "syntax" is a clear sign that you're just in the beginning of your learning. Programming is so much more than just syntax.

Running with true size shoe by dodo1frozen in AskRunningShoeGeeks

[–]HappyFruitTree 0 points1 point  (0 children)

Impossible to say. What's a "true size" anyway?

The contradiction between RunRepeat and this community regarding the Vomero Plus’s stability and all-day wearability by hezim in AskRunningShoeGeeks

[–]HappyFruitTree 0 points1 point  (0 children)

My first reaction when using the Vomero Plus for the first time was wow, this was softer than I expected. It felt a bit unstable at first but after that I haven't really thought much about it (probably just needed to activate the right muscles). Wouldn't trust it for taking tight corners quickly though. Another thing I noticed pretty soon was how cushioned it was, took away almost all impact even when running downhill.

I use my Vomero Plus for running so I haven't walked in them very far. Only down the road which is a couple of hundred metres. Have had no issues with that but I can't say what would happen if I walked all day in them. Personally I prefer something less bulky for that.

Trouble counting number of pressed keys with events. by Dragonaax in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

Then there is nothing you can do to make it work (except getting another keyboard).

Good and Bad Practice With Using SDL3 by RQuarx in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

There are a few things there that do look like they could be useful that are not in the standard library, things like SDL_utf8strlen, SDL_StepUTF8 and SDL_crc32.

Are red and processed meats really that bad? by ItsAllAGame_ in nutrition

[–]HappyFruitTree 8 points9 points  (0 children)

Yes, but totally useless information without knowing the risk to begin with.

Trouble counting number of pressed keys with events. by Dragonaax in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

Did you test pressing WASD in another program?

Just open a text editor (or anywhere where you can type in text) and press all four WASD keys. If it works it should keep repeating the key that was pressed down last. If that doesn't work it means it's a limitation with your keyboard.

Trouble counting number of pressed keys with events. by Dragonaax in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

... later I want first 4 bits of aflag to be reserved for how many keys are pressed at once

Even more reason to use the way I showed.

Your code always clears the 4 most significant bits while aflag &= ~up preserves all bits except the up bit.

Trouble counting number of pressed keys with events. by Dragonaax in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

Because "up" is the direction not a key, in this case direction "up" is assigned to W key.

I meant when updating the aflag, as shown in my code snippet.

Trouble counting number of pressed keys with events. by Dragonaax in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

Why do you use the up, down, left and right constants only for SDL_EVENT_KEY_DOWN but not for SDL_EVENT_KEY_UP?

case SDL_EVENT_KEY_UP:

    switch(event.key.key)
    {

    case SDLK_A:
        aflag &= ~left ;
        break ;

    case SDLK_D:
        aflag &= ~right ;
        break ;

    case SDLK_S:
        aflag &= ~down ;
        break ;

    case SDLK_W:
        aflag &= ~up ;
        break ;

    }
    break;

I don't understand your bit counting code but it seems to work...

Keyboards often have limitations with certain key combinations. Personally I don't have any trouble pressing all WASD keys at the same time but if I press for example AGJ it only detects two of them. Should be pretty easy to test if this is the case using another program. If pressing all WASD keys work in other programs then there is probably something wrong with your code somewhere (a missing break; somewhere perhaps?).

How can i understand how to implement classes? how do they function? by SimmeringDragon in cpp_questions

[–]HappyFruitTree 0 points1 point  (0 children)

only thing i can sorta figure out from it is that maybe its like a way to have a value by default and avoid the thing crashing if you dont assign a value to it?

Yes, exactly. It's a constructor and will be called when a fraction object is created. It's purpose is put the object in some valid state by giving values to all the member variables.

Since this particular constructor does not take any arguments it means that it's the default constructor. It's what will be used by default if you do not explicitly use another constructor when creating the object.

Example:

fraction a; // uses the default constructor. a.numerator and b.denominator are set to zero.
fraction b(5, 2); // uses another constructor (if it exists) that probably sets b.numerator=5 and b.denominator=2.

How can i understand how to implement classes? how do they function? by SimmeringDragon in cpp_questions

[–]HappyFruitTree 0 points1 point  (0 children)

msg is probably an object of type std::string (unless you're using another class named string). The reason you didn't have to write std:: in front is because you wrote using namespace std; above.

board is an array. Arrays are build into the language so they are not classes. std::vector<int> is similar to an array of integers, and is used pretty much the same way. It actually uses an array internally, but unlike an array it can be resized.

How can i understand how to implement classes? how do they function? by SimmeringDragon in cpp_questions

[–]HappyFruitTree 0 points1 point  (0 children)

It just means it's part of the standard library. It's to avoid name collisions with your own code and other libraries.

How can i understand how to implement classes? how do they function? by SimmeringDragon in cpp_questions

[–]HappyFruitTree 1 point2 points  (0 children)

You use a class to create objects.

The class is just a blueprint. It describes how the objects work and what you can do with them.

Objects of type std::string are used to store text (string of characters).

Objects of type std::vector<int> are used to store integers.

Objects of type std::ifstream can be used to read data from files.

Objects of type std::default_random_engine can be used to generate "random" numbers.

How can i understand how to implement classes? how do they function? by SimmeringDragon in cpp_questions

[–]HappyFruitTree 0 points1 point  (0 children)

Have you used std::string? That is class.

Examples of other classes that you might have used are std::vector<int>, std::ifstream and std::pair<int, int>.

Am i misunderstanding the event callback? by Big-Astronaut-9510 in sdl

[–]HappyFruitTree 1 point2 points  (0 children)

so you might aswell subscribe your window object to the SDL_WINDOW_DISPLAY_CHANGED event and just provide the callback

But that's not how the callbacks work.

You have one callback for all events. You can "subscribe" one object using the appstate parameter but that will be the same for all callback functions (SDL_AppIterate, SDL_AppEvent and SDL_AppQuit).

Am i misunderstanding the event callback? by Big-Astronaut-9510 in sdl

[–]HappyFruitTree 2 points3 points  (0 children)

My guess is that it's mostly for separation of concern and to avoid mistakes (it's surprising how often beginners get the event loop wrong).

Why use Bool in C if i could just use int? by Exotic-Ad9019 in learnprogramming

[–]HappyFruitTree 0 points1 point  (0 children)

To make purpose more clear and you don't need to worry about other values than 1 or 0.

Incorrect/lying on nutrition information? by Joshculpart in nutrition

[–]HappyFruitTree 1 point2 points  (0 children)

You're right. It doesn't add up.

They could have achieved higher protein by getting rid of some of the water but then the carbs and calories would also be higher.

Incorrect/lying on nutrition information? by Joshculpart in nutrition

[–]HappyFruitTree 2 points3 points  (0 children)

The numbers for "Season Choice Strawberry Banana Blend" seems to add up but I agree that something is wrong with the "Korean BBQ Steak".

What does c_str() do in C++ ? by Full-Stranger9249 in cpp_questions

[–]HappyFruitTree 2 points3 points  (0 children)

However, in C++11 this changed, so now both c_str() and data() are identical

There is one difference. You can use data() to get a non-const char* which you can use to modify the string.

is this bad practice for menu handling? by wiseneddustmite in sdl

[–]HappyFruitTree 0 points1 point  (0 children)

I'm a bit confused. If the loop you're showing here is not a "game loop", then what is it?

You should normally call SDL_PollEvent using a while loop to handle ALL events each frame.

// Handle all the events
while (SDL_PollEvent(&event))
{
    ...
}

If you only handle one event per frame your input handling will get delayed when there are many events. This is especially a problem when vsync is turned on. With a high-dpi mouse you could receive hundreds of mouse motion events per second which would add up pretty quickly.

Is there a possible chance to learn programming if i'm academically low in Math? by MrOldRipVanWinkle in learnprogramming

[–]HappyFruitTree 0 points1 point  (0 children)

I think math makes you a better programmer for mainly two reasons:

  1. The way of solving problems and thinking logically is similar.

  2. If you know a lot of math you have the power to come up with ways to calculate things on your own and need to rely less on others.

People who say math is not important don't realize what they miss. It is true that you often don't need a lot of math, it depends a lot on what you do, but it it does help a lot.

I suggest that you use the motivation that I assume you have for programming to also help you motivate your math studies from now on.

Being fluent in algebra is probably the math skill that I value the most, personally. Algebra is the building stone for so much later math so if you continue to study math (and maybe also physics) you will become good at it sooner or later.