New answers tagged c++
2
votes
Binary file reader and writer
Missing error checking
There are many things that can go wrong when operating on files. You only check if the file was opened correctly, but things can also fail when reading, writing and even closing ...
2
votes
Recreating Minesweeper
There are already some good reviews from the C++ point of view. So let me give suggestions from a software architecture point of view.
The code scores an absolute zero from an architecture point of ...
1
vote
Asynchronous OOP-based networking using the Epic EOS SDK
Naming things
There are several things that are named confusingly. Names should be precise and concise; they should convey quite clearly what they stand for in one or a few words. Prefer to use ...
2
votes
A recursive_minmax Template Function Implementation in C++
Bug
You iterate the range twice, once for each partial result, which is forbidden for a simple std::ranges::input_range.
You need at least a ...
1
vote
Accepted
A recursive_minmax Template Function Implementation in C++
Separate concerns
You are not following the principle of separation of concerns. Whenever you write a recursive_foo() function, you should separate the concern of ...
1
vote
A simple threadpool in C++17
Incorrect #includes
You have lots of unnecessary #include statements, for example ...
6
votes
Accepted
Binary file reader and writer
Here are some things that may help you improve your code.
Avoid redundant code
The BinaryFile class adds very little other than some error messages. I'd suggest ...
2
votes
Accepted
Re: C++ 4X Game
Just seperating the game_logic from input processing has made a huge difference in terms of code clarity. In this review, I will start with nitpicks with the ...
3
votes
Accepted
C++ printing library with templates
C++23 and the {fmt} library can print ranges
I was mad C++ did not have support for printing containers.
C++23 will have the ability to print the contents of containers, and even better of any range....
2
votes
Accepted
Implementing an Object type in C++
Use std::variant instead
With your code you have to write a visitor like this:
...
3
votes
Accepted
Spatial radius search in Boid simulation
Nice problem!
I gotta tell ya, QuadTrees is definitely the appropriate datastructure.
And it's just not that hard.
Let coord be the bit interleaving of ...
3
votes
Spatial radius search in Boid simulation
The slowness comes from drawing
Your query() function is actually quite efficient. The problem comes from drawing the boids. If you remove the calls to ...
9
votes
Accepted
Gaussian elimination algorithm in C++
Adding to pacmaninbw's answer:
Naming things
matrix2 is not a matrix, it's a vector. I would just call it a vector to avoid any confusion. Of course, since you used ...
12
votes
Gaussian elimination algorithm in C++
Don't Mix C Language I/O with C++ I/O
The code is using both printf() statements combined with std::cout, this is generally a ...
2
votes
Terminal Based Game [v2]
Here are some things that may help you improve your code.
Use the required #includes
Within GameField.h, the code refers to <...
1
vote
Casino Number Guessing Game
seems pretty solid, I only have 2 small things to say: first inside bool continuePlaying() you don't need Ternary Operator you can just write it as ...
1
vote
Accepted
Lazy/deferred OOP-based networking using the Epic EOS SDK
Separate concerns
Try to separate concerns in your code where possible. For example, your QueueCommands deals with too many things at the same time: it is a queue, ...
2
votes
Terminal Based Game [v2]
I couldn't read everything, but I have several things to say:
Beautiful usage of std::count here: ...
2
votes
C++ implementation of a concurrent queue and of a thread pool
Remove empty()
The result of empty() is a lie. Consider that between returning the result and the caller looking at it, some ...
0
votes
Accepted
ReadDirectoryChangesW Improvements
Simplify the interface
Do you really need all those public member functions? It looks like processedFilesCount() and ...
1
vote
How to interface a "pull" library with a "push" library using callbacks
You are using a busy-loop to wait for publish_count to be incremented by the interrupt handler. In general, this is a bad way to wait for something to happen, as it ...
2
votes
Terminal based game - walking and collecting points
Point class:
Consider using an existing math library (e.g. glm). It can be more complicated to set up initially, but provides things like simple math operators (e....
0
votes
C++ ring buffer using some C++ 17 and coming C++ 20 std::span
As long as the index values are not insanely high, you could use recursion and still have odd size arrays.
...
-1
votes
Parser Composition - a parser directive for Boost Spirit X3
@Justin, I'd suggest filter_input as a more descriptive name since
that's, in essence, what it does. It changes the input to the
Secondary parser using the std::...
1
vote
"Rock Paper Scissors" game
The code looks good and well-organized.
Here are a few suggestions:
Use const wherever possible to make the code more readable and safe. For example, in ...
1
vote
Accepted
Partial specialization of class template with minimal code duplication
I would avoid inheritance and go for the implementation in the addendum. However, you can significantly simplify it:
It's fine to unconditionally use std::ref() in ...
8
votes
Accepted
"Rock Paper Scissors" game
Overview
I don't like how you are simply passing strings around for the values. Its simple but not very optimal. I would create some enum types to represent the different states (Win, Lose, Draw) and/...
7
votes
"Rock Paper Scissors" game
Computing pcSelection can be factored out into a separate function.
If users enter an invalid choice, promptUserInput still ...
3
votes
Integer endianness types for protocol structures, take 2
Adopt C++23
Since the code was written, C++23 introduced std::byteswap(), which enables a completely different implementation for the common case where native-...
4
votes
Accepted
4
votes
Accepted
Class for locking shared disk directory
This is not safe
Let's consider two threads that each call tryToLock() at the same time, and there is an expired lockfile on the disk:
...
4
votes
Class for locking shared disk directory
spec
at first glance works without errors.
I'm willing to believe that's true.
You've not made it easy to verify it at second glance.
What I'm looking for is a concise specification
of intended ...
5
votes
C++ heap allocator using an explicit free list
Overview
Must say that when reading complex code, the first thing I want to read is the constructor and destructor. Personally I always put these first in a source file. Without understanding these ...
5
votes
Accepted
C++ heap allocator using an explicit free list
You are overthinking alignment
malloc() and new will return a pointer that is already suitably aligned for any built-in type, ...
3
votes
Accepted
Multi producer/consumer lock-free queue
This is not lock-free
Unfortunately, your queue is not lock-free. Basically, your _canUpdate is used as a lock. Consider a thread that has taken the lock, so it's ...
0
votes
12
votes
Accepted
Calling fgets() twice
Well, for starters, you really want to decide whether you are coding in C or C++. You #include <iostream>, but make no use of any iostream functions (...
Top 50 recent answers are included
Related Tags
c++ × 9376c++11 × 1703
performance × 1057
beginner × 884
algorithm × 832
c++17 × 548
programming-challenge × 480
object-oriented × 479
c++14 × 470
multithreading × 410
template × 404
strings × 397
linked-list × 322
game × 301
reinventing-the-wheel × 298
c++20 × 278
template-meta-programming × 267
pointers × 254
memory-management × 253
vectors × 248
array × 216
time-limit-exceeded × 215
sorting × 194
graph × 174
tree × 173