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.

learn more… | top users | synonyms (2)

4
votes
2answers
78 views

Test if a binary tree satisfies the BST property

I implemented code logic provided in the EPI book to determine if a binary tree is a BST. There were two approaches, therefore I used polymorphism for the common parts. I'm also using templates. I ...
-2
votes
0answers
20 views
-1
votes
0answers
25 views
4
votes
2answers
104 views

Linked list, pointer practice

The vast majority of my experience is in writing managed code. I'm putting myself through C++ boot camp right now and trying to really wrap my head around pointers and memory management in general. ...
7
votes
2answers
121 views

Parsing HTTP Headers in C++

I am building a web server from scratch and trying to make certain tasks faster by embedding C code into the mix for performance. Specifically I'm worried about how the ...
3
votes
1answer
45 views

Command manipulation functions for a toy shell program

I am writing a small program that is supposed to act as a shell of some sorts. It operates off of a few basic structures, one of them being a command, a ...
4
votes
2answers
104 views

Implementing a shared_ptr class in C++

I'm trying to write my own shared_ptr/weak_ptr implementation in C++. I have the following requirements: I do NOT need support for the following: multithreading (synchronisation) support for ...
3
votes
1answer
50 views

Attempt at Smart Pointer Implementation

Here is a smart pointer that "knows" the number of existing instances: smart_ptr.h: ...
6
votes
1answer
146 views

C++ Linked list with smart pointers

This seems to work fine, but I'm very new to C++ and would like any suggestions for improvements. Areas I have the most trouble with are: Namespacing (honestly, it's still half looking stuff up and ...
5
votes
1answer
75 views

C++ maybe pointer type implementation

Motivation This is intended to implement a C++ maybe_ptr type that can either hold a pointer to an underlying type T or a ...
1
vote
1answer
42 views

malloc and free of a char-array

I wrote a function to reverse a char-array (string). Since I'm beginner and didn't work with malloc and stuff before, maybe someone could take a look, if this is ...
1
vote
0answers
43 views

Thread class that uses std::unique_ptr

I have implemented a class which encapsulates a thread of execution and provides an interface to send messages to it. It is based largely on an article written by Herb Sutter in 2010. It also uses the ...
2
votes
1answer
63 views

string-length, structs, pointers in c

So since I'm just new with learning C (this is the second day now), I'd be very happy if someone could review my code: what I tried to do is: create a structure containing a string- and a length-...
7
votes
3answers
1k views

String comparison using pointers

This piece of code works fine. But I'm wondering if it can be done in a more efficient way. More specifically, this part (*(s1 + i)) if it possible to force it to ...
0
votes
2answers
109 views

Custom STL Vector in C++

This is my first time I tried to implement a custom STL vector with iterator. I have some questions: What are better ways to write an iterator? I know that there is a ...
3
votes
1answer
132 views

Linked List: Smart Pointer Implementation

Linked list using smart pointers, iterative implementation. It amazes me how a std::forward_list does not allow the list to be walked until the last pointer is <...
0
votes
1answer
101 views

Implementing a single linked list using smart pointers (replace std::shared_ptr with std::unique_ptr)

As an example code I've given here, I have the feeling the use of std::shared_ptr is wrong and should be replaced using a ...
0
votes
1answer
117 views

Smart Pointers Queue Implementation

To practice around with C++11 smart pointers I was trying to implement a simple Queue to go beyond a simple Linked List. The fact that the _first and ...
3
votes
1answer
84 views

Smart Pointers with Reference Counting - C++

I am trying to improve my general skills in C++ so I plan to write versions of shared_ptr and unique_ptr from scratch. I wrote a version of shared_ptr with reference counting and I was wondering for ...
3
votes
1answer
99 views

Converting Integer to dynamically allocated Char array, digit by digit using pointers

Problem: Write a function to convert Integer to String, using only pointers, without array indexes, string must be dynamically allocated. ...
3
votes
1answer
62 views

Book record system

I'm still new to programming. I have made a book record system and I just wanted some coding review if there is any mistakes I should fix or any improvements that are needed. Here is the code I made <...
11
votes
2answers
535 views

Learning pointers by implementing a basic linked list with tests

I wanted to learn about pointers and someone suggested that I give C a try, so I went through Linked List Basics from Stanford CS library, implemented some of the code (and tried to improve the code a ...
7
votes
3answers
210 views

Multiplayer GameObject design

I created a really basic game class. A game has GameObject instances, which currently have a position only. This code is running on the client, and in each loop ...
4
votes
1answer
37 views

2D matrix - splitting the matrix in two parts with equal number of elements

The elements in the matrix are either 'M', 'G', 'P' or '.' and the algorith must write out all possible ways of splitting the matrix so it has equal number of M, G and P on each side. It's a task we'...
-1
votes
1answer
60 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
99 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 ...
1
vote
3answers
54 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
106 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
89 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
93 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
41 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
370 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
65 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
133 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
63 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
108 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
70 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
166 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
34 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
41 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
101 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
109 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
177 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
52 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
542 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
58 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
95 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
327 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
56 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
29 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 ...