Hot answers tagged

10

The group of methods which belong to one parser are tightly coupled because of the nature of the problem. The parser has some state to manage which is shared between all those functions. So putting that state into a variable outside the local scope of those functions makes perfect sense. Passing the state from one function to another would just result in two ...


4

You have basically the following options: 1.) Do nothing. Maybe the result is precise enough for your use case. Note when using floating point operations, it is quite normal you have to deal with some rounding errors. I would recommend to have a look at What Every Computer Scientist Should Know About Floating-Point Arithmetic. 2.) If your use case involves ...


4

Both algorithms are usually expressed using recursion, yet the actual implementation is then often done using iterative techniques. This sometimes leads to confusion, as the algorithm you present pre-fills a table with the desired values iteratively and then just returns the value in the one cell we are looking for. Let's try to write up the recursive ...


2

I generally try to separate out groups of files by related functionality. For a game, you're likely to have files related to various aspects of a game such as: -> source -> game -> rendering -> renderer.cpp -> renderer.hpp -> material.cpp -> material.hpp -> mesh....


2

Errors are there to stop you doing things are not allowed like walking across Niagara Falls on foot (without any ropes or anything). It just can't be done, so the compiler say "No". Warning are there for things that you might get away with, but you probably shouldn't try, like walking across Niagara Falls on a tightrope. Yes, some really, really skilful ...


1

I don't see much (if any) reason to use any global variables. The parser functions rarely pass many parameters, because there's not normally any real dependency between them (i.e., not much you'd need to pass as a parameter from one to another). At least as typically implemented, the only dependency on the outside world is in the lexer, where it needs to ...


1

Would using global variables in this case be fine? Sure. It's a hobby project, meaning maintainability isn't a super high priority. Your examples use them, so if you also use them the examples will be easier to follow. Or is there a better alternative? That said, you are totally right that global variables are to be avoided and will cause you all sorts ...


1

However with the embedded constraints of no dynamic memory, no virtual calls, no delete, no free etc it looks like the only solution for achieving polymorphism is to use templates Your solution with references does not require the use of dynamic allocation (new), but it does require the use of virtual functions. If virtual functions are also forbidden by ...


Only top voted, non community-wiki answers of a minimum length are eligible