C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.
3
votes
1answer
155 views
std::vector memory manipulation - Serialization - DeSerialization
This is my code and I would like to get it code reviewed. It is functional and behaves as expected.
I pass some basic types to Serialize function and then deserialize the output to get back the ...
3
votes
2answers
72 views
Does this List implementation in C++ perform proper memory management?
The full code is located here: https://gist.github.com/4521540
It's a dummy List in C++. My concern is with freeing up memory.
It doesn't crash when I run my code. It looks like my if/else covers ...
5
votes
5answers
235 views
Is it possible to optimize these functions any more?
I am running a simulation with 250 interacting agents and have a few functions that are called over and over again. Even with precomputing all distances between agents before the N^2 (250x250) ...
8
votes
3answers
268 views
Please review my exercise about linked lists
I'm learning C++ by myself and therefore I have no direct access to a mentor. This is the reason why I'd love if you guys could take the time to do a peer code review.
I am very much aware, as per ...
4
votes
2answers
506 views
Designing a state machine in C++ using STL, please improve
I have this working code for C++ state machine using STL (not using boost state chart) The purpose of posting is two fold.
To share a simple and working code C++ state machine using STL for sparse ...
5
votes
1answer
101 views
Playing Cards in C++
I am currently learning C++ (note: I am using C++11) and have begun working on a small project to practice what I've been learning. This project is a deck of cards that I hope to use later to create ...
3
votes
1answer
149 views
Review my Vector implementation
This is intended to be a simpler replacement of std::vector, written for entertainment.
It should be as fast or faster then std::vector, but does not need to have as much features.
It should also be ...
-1
votes
1answer
47 views
Am I using the Input/Output Stream Library right? [closed]
I am a newbie in C++ programming and I'm trying to use std:: because someone told me that is a good habit rather than putting in using namespace std; because it pollutes the global namespace. I'm not ...
2
votes
2answers
130 views
Am I using C++ Pointers and References correctly?
I am a newbie in C++ programming, I am currently reading this book called Jumping to C++ by Alex Allain, currently finished the Pointers Chapter and I am doing the Exercises at the end of the Chapter.
...
2
votes
2answers
135 views
Undirected, connected and weighted graph implementation
I was thinking in a way of implementing a graph in such that would let find a minimum spanning tree.
I have this:
Graph.h
#ifndef GRAPH_H
#define GRAPH_H
#include <list>
#include ...
0
votes
2answers
104 views
Correct way of using HBRUSHes..?
If I create a brush like so
HBRUSH hBrush = CreateSolidBrush(RGB(33, 33, 33));
and then later on, I want to change the color of the brush, how would I do this?
I googled a bit and found out that ...
4
votes
5answers
247 views
How to optimise a for loop in a factor search to run faster?
I created a program to find the largest prime factor for a given number.
The program worked but unfortunately it takes very long time to compute a huge number like 600851475143.
How can I optimise ...
2
votes
1answer
93 views
Please improve my novice c++ code
I have many thousands of image files spread around various places and would like to copy them into one directory. However, may of the files are duplicates with the same names (often thumbnails or ...
1
vote
1answer
105 views
AStar C++ implementation is too slow
My AStar Algorithm in CPP is pretty slow. I'm not sure if it because of bad implementation or just because I have way too many Nodes (I have a Field of 256x256 Nodes). It takes the Algorithm about 5 ...
1
vote
3answers
318 views
Shortest path in a grid between two points. Code optimization
I have this problem where I have to find the shortest path in an NxM grid from point A (always top left) to point B (always bottom right) by only moving right or down. Sounds easy, eh? Well here's the ...
2
votes
2answers
159 views
A* shortest path algorithm optimization request
Good day to ya'll. I had this programming excericise of mine where I had to find the shortest path to an exit in an NxM -grid maze in under a second (both N and M would be anywhere between 3 and ...
-1
votes
1answer
92 views
Readers and writers (writers-preference). I'm not sure whether my code is wrong or not [closed]
I've found on the wikipedia pseudo-code, so I've decided to try it.
That's the Wiki's code:
int readcount, writecount; (initial value = 0)
semaphore mutex_1, mutex_2, mutex_3, w, r ; (initial value ...
1
vote
1answer
42 views
Function to erase original element but also linked
I have a list of pointers to objects where some of the objects contain a pointer to another object. When I remove an object in the list which has a linked object I need to remove them BOTH. I also ...
1
vote
0answers
99 views
A pointer vector sorted by its member function
Ask for suggestion on a random accessed vector with allocated elements sorted by its key obtained from its member function.
I use it with Qt tree view where the access, add and deletion of tree items ...
4
votes
1answer
183 views
A C++11 `Any` Class
A C++11 Any Class
Overview
We show a C++11 class Any, that is a polymophic wrapper capable of holding any type. (It is loosely based on boost::any)
In particular this is useful when you want to ...
4
votes
2answers
210 views
How to further optimize this code for 3n + 1 problem?
The problem can be viewed here, since it's styled. I don't think I should just copy and paste.
And here's my code. I implemented recessive function and dynamic programming to solve it.
It can ...
8
votes
1answer
207 views
Is splitting to small classes good?
I have materials.
class Material {...};
class ConcreteMaterialA : public Material {...};
class ConcreteMaterialB : public Material {...};
I want it has a name
class WithName
{
public:
const ...
0
votes
3answers
191 views
Run Length Encoding
Given an input string, write a function that returns the Run Length
Encoded string for the input string.
For example, if the input string is “wwwwaaadexxxxxx”, then the
function should ...
2
votes
3answers
177 views
scope exit something wrong?
Is there something wrong with this code?
#pragma once
#ifndef SCOPEEXIT_HPP
# define SCOPEEXIT_HPP
#include <utility>
/* This counts the number of args */
#define NARGS_SEQ(_1, _2, _3, _4, ...
1
vote
1answer
63 views
What should be the reason to get Wrong Answer in the UVa site for this program? [closed]
Here you'll find the problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=614
#include<iostream>
#include<stack>
...
0
votes
2answers
89 views
Review request: unw_graph class (unweighted graph)
Here is my new stl-like implementation of an unweighted graph. Could you please tell me what member functions should I include to my library? Thanks in advance.
file: unweighted_graph.hpp
#include ...
3
votes
2answers
102 views
Custom nullptr_t class
I tried to write a nullptr_t class based on the official proposal to be used in C++03 only. The only differences with the proposal are that we can compare two nullptr_t instances and that it is ...
5
votes
1answer
165 views
Vector of derived classes
Everyone knows you can't put a Derived in an std::vector<Base>. I decided to implement a collection which does allow you to do this:
#pragma once
#include ...
2
votes
3answers
168 views
Is there a faster way to clear the screen?
I'm currently clearing my console window with this piece of code:
void clrScr()
{
COORD cMap =
{
0, 3
};
if(!FillConsoleOutputAttribute(hCon, 0, 2030, cMap, &count))
{
...
1
vote
2answers
154 views
How to Format Clean Accumulation Code?
I often find myself writing methods in languages such as Java or C++ that are only meant to loop over an array or something similar, accumulate the values, and then return the total. The problem is, ...
1
vote
0answers
272 views
JPEG compression, DCT Algorithm verification
Here is the code I am using to apply DCT on 8x8 blocks but I'm not sure if this is correct. I have tried to follow Wikipedia's formula as closely as possible. Please let me know if there are any ...
0
votes
1answer
241 views
Free implementation of “bounded priority queue” in C++ (with code)
I was searching for a free implementation of a "bounded" priority queue. The algorithm has been discussed many times on stack overflow (e.g. Free implementation of "bounded priority queue" ...
1
vote
0answers
107 views
Review: C++ Algo - Function
See Review: C++ Algo - Style
I'm looking for a review of the function of this code, answers to the above question which also describes the code use focus on style instead.
Below is the updated code ...
0
votes
0answers
82 views
Feedback on Arduino class for LED circle animations
I'm fairly new to Arduino and C++ in general, coming from a heavy Python background. The code below is functional, but my lack of C++ knowledge is keeping me from spotting any errors in style, idioms ...
-1
votes
1answer
206 views
C++ program Segmentation fault for Selection Sort in ascending order [closed]
The program compiles but the numbers do not sort and it ends with "segmentation fault". Help? I am using a c++ compiler
void Selection_sort(int [], int);
void Swap (int*, int &, int &);
void ...
-1
votes
1answer
65 views
Can you please review my code? It won't output correctly [closed]
The following code will not output correctly. Could you please review it? Here is what I've been asked to do.
This program will include error trapping with try and catch.
Put a throw in each ...
2
votes
2answers
153 views
C++ code to launch a Windows 8 app
This is my first C++ in many years. It's based on some stuff I found on the internet, including a Microsoft article on a similar topic. But I'm sure there are C++ idioms that might make this better or ...
2
votes
1answer
192 views
How to optimize multiple threads?
I am trying to reduce the total execution time of my code.
I have a GPS system which calculates routes between two points, and returns all points in between them.
I did a simple profile and the ...
3
votes
2answers
193 views
Review: C++ Algo - Style
Can this code be reviewed?
I've updated this question to be about code style only, as all of its answered focused on this aspect. For the codes function, see Review: C++ Algo - Function
'algo' is an ...
0
votes
2answers
122 views
C++ interface design - does this look logical as base message handling class
I am designing a program which encodes / decodes protocol messages to/from various bits of hardware.
//base protocol class - interface only
//ref_type is a smart pointers class - not really so ...
1
vote
1answer
110 views
C++ Design Struct vs Class [closed]
I am writing class CollectingClass which collects much data in private members and prints them out later.
To encapsulate all the private members, I decided to create a struct Data, keeping all the ...
4
votes
1answer
319 views
Multi-Threaded Game Loop. Is it thread safe?
Below is a start on a multi-threaded game loop and I just wish to confirm my code is going in the correct direction, and if not, is there any way it can be improved? I have good experience in game ...
6
votes
4answers
1k views
c++ implementation of Trie data structure
I use Trie data structure to solve the following problem:
Given an array of words, print all anagrams together. For example, if
the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then ...
0
votes
1answer
137 views
use trie data structure to solve the problem of clustering anagrams
Given an array of words, print all anagrams together. For example, if
the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output
may be “cat tac act dog god”.
The following is my c++ ...
1
vote
1answer
52 views
Comparing sets of different types using variants
First off, I will try to explain the problem and then I will show you the code I have come up with so far.
I've got a list of properties. Each property has a tag of type int and a value of one of the ...
1
vote
0answers
221 views
Mingw, wcout and locales
I've recently had to print some national symbols in windows console using Mingw and found, that I got nothing in the output, if I use wide strings.
So, I studied the problem and found out that it is ...
2
votes
1answer
62 views
Explicitely passing a parameter by reference in C++03
In C#, passing a parameter by reference can't be ignored:
// C#
void foo(ref int p_value) ; // passing an int by reference
void bar()
{
int i = 0 ;
foo(ref i) ;
}
In C++ (and as far as I am ...
1
vote
1answer
64 views
How to optimize this CUDA code?
Look the code:
void OpenNNL::calculateNeuronsOutputsAndDerivatives(double * inputs, double * deviceOutputs, double * deviceDerivatives)
{
int inputsCount = _inputsCount;
double * deviceTemp;
...
4
votes
1answer
267 views
Find All Substrings Interview Query in C++
The following is my code for printing all the substrings of an input string. For example, with "abc", it would be "a","ab","abc","b","bc","c". Could someone please review it for efficiency (and ...
2
votes
5answers
217 views
C++ - How could I improve this rude word filter?
This program will filter the input by replacing matching bad words with "Bleep!". I'd like the code to be more concise and C++ style where possible. One thing that bugs me is the was_bad flag I think ...

