In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.
-1
votes
1answer
31 views
Using shared_ptr as class member [closed]
I have already got the answer for my previous question, and I decided to use std::vector<int> instead of int *. I have ...
4
votes
3answers
87 views
Simple wrapper for member function pointers with known signature
I always wanted to know how to pass member functions as arguments, and then I stumbled across templates that could automatically deduce types, and so I rejoiced! This is used in a Publisher-Subscriber ...
-3
votes
0answers
15 views
(C++) Error when delete double pointers from memory, cause memory leaks [closed]
I had a project who creates players about game. All their informations come from a text file. For this, all works fine. But I have few problems when I used double pointers to allocate all the players ...
1
vote
3answers
47 views
Implementing my own shared-ownership double-indirecting smart-pointer
I am implementing my own double-indirecting shared-ownership smart-pointer because I needed a way to replace the managed object a group of smart-pointers is pointing to with a new object (it's the ...
4
votes
1answer
87 views
Template double ended queue (deque) implementation using dynamic allocation C++
I have written my own deque class to get a better grasp of C++ pointers and memory management. The following code is part of a larger 2D isometric game I am developing. It compiles and runs fine using ...
2
votes
2answers
38 views
Inserting into a binary search tree in C
I am in the process of refactoring this simple binary search tree code responsible for adding new values:
...
3
votes
2answers
77 views
Callback system for events in a window
I have written a simple window event capture wrapper that gets events that happen to the window, and can be checked anywhere in the program through a global class. I wanted to be able to create a ...
-1
votes
1answer
38 views
Trying to build a bare metal stack on the stack [closed]
I'm trying to implement a stack data structure, but not on the heap but using the stack. Also not using any Node or Element struct but raw ints. Is this feasible? This is my code (with debug printfs) ...
2
votes
2answers
184 views
A doubly linked list implementation using C++ smart pointers
I am new to "modern" C++ and decided to learn about smart pointers by implementing a doubly linked list.
I have a few problems with this code: Should the tail pointer be a weak pointer? Should the ...
4
votes
1answer
55 views
Linked List simple implementation
I made a simple linked list in C with the following functionalities:
Create(creates the list); Find(searches for an element in the list); Insert(inserts a value at the beginning of the list); Destroy(...
3
votes
1answer
87 views
C++ lock wrapper class around pointer
I have created a class which wraps pointers and behaves like a pointer would behave, minus a few cases. It is a lock wrapper class which simply locks before usage of the pointer and unlocks once the ...
0
votes
1answer
58 views
RAII object for releasing pointer with arbitrary function
The following class is a sort of "smart pointer" that can be used for automatically releasing pointers:
...
3
votes
2answers
87 views
shared_ptr code implementation
I have never used std::shared_ptr before and I don't really know how this smart pointer actually works but I decided to create one to verify my knowledge. Here is my code :
...
1
vote
1answer
59 views
List implementation with shared_ptr using C++11
I wrote list, which I think is more elaborate than usual. I would like to ask you for some tips, criticisms, and general feedback about my code.
...
4
votes
1answer
154 views
Find the first occurrence of a substring in a string
This is a simple version from the function strstr. It returns the address of the first occurrence of the substring s2 in s1. I want to know possible problems in the code, and how to improve it, in ...
0
votes
1answer
33 views
Implementation of the binary search algorithm [closed]
This is my first implementation the binary search algorithm. I have tested it and so far it is okay. But I need an experienced eye to review the code and recommend best practices.
...
3
votes
1answer
39 views
Exercise to create an insertString function to linked-list
Working from 'Programming in C' by Kochan. I'm on an exercise in the chapter 'Pointers'.
This was the exercise:
'Write a function called insertEntry() to inset a ...
2
votes
0answers
87 views
Intrusive weak pointer
WeakPtr can point to any object provided it inherits from WeakBase. So, for example, you could use it to observe an object ...
5
votes
2answers
84 views
NamedPoint class using unique_ptr for members
After reading this old article from 2001 I have tried to implement the class from it using unique_pointer.
An author's claim is that C++ is not appropriate for ...
6
votes
1answer
166 views
Using pointers and type cast to break up integers into byte array
Usually I don't start using pointers for a few microseconds here and there.
But with this implementation I started getting results of factor 2.
...
1
vote
1answer
48 views
Using a map of shared_ptr instead of single pointers as class members
I'm working on a node.js bindings for libcurl. As libcurl accepts many callback functions as options (like CURLOPT_READFUNCTION for example), I had to store their respective javascript callbacks ...
11
votes
2answers
522 views
Beep-beep I'm a car factory
I have implemented to following generic factory in C++11 using smart pointers and I would like to get some feedback about it.
(Please note that I can't use C++14)
Due to company policies I have to ...
4
votes
1answer
49 views
Polymorphic pointers-to-functions whose parameters are void pointers as arguments in C
My question is about this sort of table that's simplified here. Often, I find myself putting this element, (int (*)(const void *, const void *))&strcmp for <...
2
votes
1answer
92 views
Pointer lists for a C++ garbage collector
The problem
My intention is to have a class A and class B. class B has a ...
4
votes
2answers
201 views
Doubly linked list reimplemented with smart pointers
I need some suggestions on my reimplementation of a doubly linked list with smart pointers since I'm new to smart pointers in C++.
I read some docs on smart pointers and found out there are ...
-3
votes
1answer
52 views
Creating a struct
Mat told me to create a struct
create a struct for the individual commands and arguments. It should
have something like the "executable" name, number of args and arg
list. Create a few ...
0
votes
1answer
27 views
C function for copying array into matrix
I want a matrix that can grow dynamically and build up a structure in RAM as input arrives from standard input och terminal (shell). First I tried with a matrix like ...
7
votes
2answers
195 views
An optional<T> implementation
This is an implementation of optional<T> from C++17, it is mostly standard conforming.
I'm looking for a review on efficiency, correctness and performance.
...
0
votes
1answer
72 views
Shell command line program
I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
4
votes
1answer
88 views
Avoiding pointers in this C++ linked list
As I know it is not good idea to have so many pointers in c++ code.
But I have written this simple implementation of linked list in c++ and there are many pointers in it, how can I improve that?
Also ...
1
vote
1answer
86 views
Operator Oveloading: “+” and “==” for two classes
I have one class Number (base class) and two child class Fraction and ...
6
votes
3answers
133 views
View programming pattern in C++ without raw pointers
I'm trying to achieve, for lack of a better term, a "view" pattern in C++. It's probably most comparable to "views" in the Database world, where one can make a query, and then perhaps aggregate the ...
-1
votes
1answer
54 views
&(array[index]) vs (array + index) [closed]
So I'm working with a function that returns a pointer to a list item. Right now, I'm using:
...
4
votes
2answers
259 views
Generate all permutations in C
I have written code for generating all the permutations in C as explained here. How can the code be optimized? Are there any memory leaks?
...
4
votes
1answer
297 views
(C++14) Handling state in C-style function pointer callbacks
I'm having some issues coming up with a sensible solution for using shared state in a C-style function pointer. I am using GLFW to handle my OpenGL context and have created a thin wrapper around all ...
2
votes
0answers
64 views
Transform and transpose byte[] of 32bit image data in 24bit array image data
I would like to know if someone can think about a better solution for doing this stuff.
I have an array of raw bitmap data in 32bit format (RGBA). I need to transform and transpose this array into a ...
2
votes
2answers
2k views
ShoppingCart and Item Classes
I've built a class for an e-commerce Item, and the ShoppingCart class for checkout functions.
The thing I'm most concerned ...
3
votes
1answer
149 views
Overloading operator ->* for smart pointers
I am implementing a smart pointer class template and I want to overload operator ->* (even if it’s rarely done). I came across Scott Meyer’s article Implementing ...
5
votes
2answers
115 views
1
vote
2answers
155 views
Read characters from stdin into an resizeable array
As first steps in C, I'm trying to write a program that reads from stdin into an array allocated on the free store, until an exclamation mark ! is entered. The ...
3
votes
1answer
24 views
Given a string, print another one without a given char
My aim is to write a C program (I must create a function) that, given a string and a character, returns another string without the given char value.
For example: ...
6
votes
2answers
172 views
Fixed-Size Memory Pool
I've been reading about Memory Pools since I came across them in the book Game Programming Complete 4th Edition, and I decided to try and spin my own since I didn't quite understand how the one they ...
4
votes
2answers
431 views
Memory management for Red-Black Tree
I've written this program yesterday, and I was reminded why I dreaded C++ before turning to Java: pointers and associated terms (like destructors, initializations and copy/move constructors) are ...
3
votes
1answer
229 views
Efficient C++ Resource Manager
This is my final attempt of making an efficient ResourceManager class, which takes care of allocating OpenGL objects (like Shader, Textures, Meshes, ...). It stores ...
-3
votes
2answers
75 views
Array to function to int arithmetic
I want to get the value of an integer from within a struct pointer. Simply: int cool = *(*(&(coolPtr->map)) + x); can this be simplified? The rest of the ...
1
vote
2answers
389 views
C++ Winsock HTTP Request Library
I'm trying to write a HTTP Request library for practice with Sockets and C++ in general. I created a seperate function to setup the struct needed to Connect() however it is now breaking and I cant ...
4
votes
3answers
1k views
DeepPtr: a deep-copying unique_ptr wrapper in C++
When using the pimple idiom it is necessary to represent your "impl" as a forward declared pointer in the header file. This necessitates a lot of boilerplate code to implement the rule of five.
...
6
votes
1answer
217 views
Random String Generation - Base36 and optimization
This is some fairly heavily optimized C#. Aside from reading like C++ code due to all of the pointers, does this pass sanity checks, and is there any way to improve it, while keeping its speed (or ...
7
votes
1answer
203 views
Cancellable futures, interaction with throwing destructors
I'm reinventing std::future from scratch (for an upcoming talk). I'd like to incorporate as many of the latest and most likely-to-succeed proposals as possible, and ...
4
votes
1answer
246 views