Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
23 votes
Accepted

Implementing a Stack with Templates and Smart pointers

Readability Please put a space after the include and before the < ...
user avatar
  • 91.5k
23 votes
Accepted

C++11 smart pointer 'library'

I'll hit the red flags first, and then review the details. ...
user avatar
21 votes
Accepted

Can I buff up your file?

1. Bugs If the open succeeds but the lseek fails (as it might if the file is a named pipe), the function omits to close the ...
user avatar
  • 49.2k
20 votes
Accepted

My implementation for std::unique_ptr

Overall Ohhhhh. Is it well-formed? It compiles, so yes. i.e. does it follow common C++ standard and patterns (for example, should private members be declared before public ones? Personally I think ...
user avatar
  • 91.5k
19 votes
Accepted

strstr() implementation

Const-correctness Since you tagged this question as c++, you must take care of const-correctness: ...
user avatar
18 votes
Accepted

Initializing and printing an array using pointers and dynamic allocation in C

There are a number of things I would change here, so I'm going to go through the process incrementally, applying changes to the whole file in passes rather than in chunks. I think this should make it ...
user avatar
  • 3,172
18 votes
Accepted

Inventorizing the universe

You don't need an include guard in Main.cpp #ifndef MAIN_CPP #define MAIN_CPP Include guards are meant to avoid a header file ...
user avatar
  • 17k
18 votes
Accepted

Array Dynamic resize in heap

If you had tagged this code as C, it would have been acceptable. Since you tagged it as C++, it's horrible. Instead of writing your own swap function, there's ...
user avatar
  • 20.9k
17 votes
Accepted

String comparison using pointers

You don't need pointers to character pointers at all: ...
user avatar
  • 25.3k
16 votes

Inventorizing the universe

I have a few questions about your design. Classes What's the purpose of using classes if all of your data and methods are public? Why bother having getters and setters like ...
user avatar
  • 11.5k
16 votes
Accepted

Minimum of two floating-point numbers

Versatility The pointer version is less versatile. If the two values come from expressions like in min_value(x + 13, 2 * y), you can't use the pointer version, as ...
user avatar
15 votes

Implementation of stack using pointers

Please fix your indentation all over the header. It should be consistent with everything else. You don't need the return 0 at the end of ...
user avatar
  • 34.7k
14 votes
Accepted

Implementation of stack using pointers

First of all, I will start with one of the most common remarks: please, do not use using namespace std;. It is especially bad if you write it in a header file since ...
user avatar
  • 19.8k
12 votes
Accepted

Smart but simple pointers

This is not unique_ptr, it is auto_ptr, which has problems, mainly that copying a value modifies it, which is counter intuitive. ...
user avatar
  • 1,619
12 votes
Accepted

Singly Linked List implementation C++

I like this. #ifndef LINKEDLIST_H #define LINKEDLIST_H But it is not very unique. If used in a big project this may clash with other guards. I usually include ...
user avatar
  • 91.5k
12 votes
Accepted

C - Learning Linked Lists, Pointer Manipulation - Store some ints, print and free memory

Naming It's unconventional to name a type with all-uppercase - we normally reserve those names for preprocessor macros, to warn readers that they need treating with care. Avoid such names for ...
user avatar
  • 57.8k
11 votes

Using std::unique_ptr and std::move

Programming / detail review Fan(Fan *peer__ = NULL); (and some more occurrences) Identifiers that contain a double underscore are reserved for the compiler/...
user avatar
  • 1,099
11 votes
Accepted

My linked list implementation in C

I suggest you rename link to next which is a more conventional name for the next linked list node. ...
user avatar
  • 25.3k
11 votes
Accepted

Finding first recurring letter in each string of a given set

Better names The variable names are too short to be meaningful. It's common to use i as an index in for-loops, but ...
user avatar
  • 18.8k
11 votes

C++11 smart pointer 'library'

Let's have a look at some examples where it fails. Rule of Three You have not correctly over written the assignment operator. ...
user avatar
  • 91.5k
11 votes

malloc in main() or malloc in another function: allocating memory for a struct and its members

Looking at the performance, the two versions should perform just about identically. The second version has one less call/return, which can save a couple of CPU cycles, but if you have it multiple ...
user avatar
11 votes
Accepted

Using smart pointers to construct Binary Search Tree

Answers to your questions Am I using std::unique_ptr correctly here? Using std::move and get? Yes, you are using those correctly. Is there any way for me to make ...
user avatar
  • 32.6k
10 votes
Accepted

Custom class for a borrowed unique_ptr<T>?

My question: Is borrowed_ptr silly? Is it a faux pas? Does it feel like a code smell? It seems a bit overengineered to me (YMMV). Do you feel I should rather do 1., 2. or something else ...
user avatar
  • 3,577
10 votes
Accepted

Printing the contents of a string array using pointers

Given that the code is really simple, I see mostly coding style issues with it. Instead of this: char *names[] = { "John", "Mona", "Lisa", "Frank" }; I ...
user avatar
  • 107k
10 votes

Singly Linked List implementation C++

don't do this: using namespace std; This will create a lot of namespace collisions. Writing std:: where you need to isn't ...
user avatar
10 votes
Accepted

Graceful thread shutdown with std::move

volatile bool thread_shutdown = false; This is definitely not correct. volatile is not for thread safety. What you want here ...
user avatar
  • 8,241
10 votes
Accepted

Binary Search Tree implementation using smart pointers

please do not using namespace std; why has Bst::findmin no prefix _? why do you use ...
user avatar
  • 871
10 votes
Accepted

malloc in main() or malloc in another function: allocating memory for a struct and its members

In C, initialization and destruction should be done at the same level of abstraction. This is important because it defines who is responsible for the memory. There are two good ways to follow this ...
user avatar
10 votes
Accepted

Hunt the Wumpus

Many of the member functions of Room can be const since they don't modify the object data (e.g., ...
user avatar

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