C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

3
votes
0answers
23 views

C++: Generating similar methods with macros

I am currently working on a project that involves Lua. For convenience, I created a wrapper class for the Lua state structure. However, I also added some methods for getting globals and table fields. ...
5
votes
1answer
56 views

Simple “nullable” template class. Are there weaknesses in the implementation?

The goal is to have fields in a class which are optional and can be determined if they are set in order to be able to leave them out of serialization. template<typename T> class Nullable { ...
1
vote
0answers
32 views

Random Generation From Sequences

With the inclusion of <random> into C++11, we can finally chuck out std::rand and start using generator with much better properties. Still, it's easy to get things wrong (uniform sampling where ...
3
votes
4answers
96 views

C++ vectors sort ascending/descending

How can I eliminate repetition from this code? std::vector<std::wstring> vec; bool descending; if (descending) { std::sort(vec.begin(), vec.end(), ...
3
votes
1answer
84 views

Fun with probability theory. Suggestions?

I want to play around with the Powerball lotto drawing history. What other probability theories could I try or what other probability class libraries exist. The code parses the file very quickly but ...
2
votes
1answer
63 views

How to design interface of deep-copy behaving pointer containers?

I want to make a container which manages big objects. which performs deep copies on copy construction and copy assignment. I also like the interface of the std containers, so I wanted to implement it ...
3
votes
1answer
35 views

C++ Url Decode Function Optimization

I have the following mock up that I need some feedback on how i might improve the url_decode function to make it faster and use less memory. There are a couple of requirements. I have to use the ...
5
votes
2answers
105 views

maximum equal in C++

When I need to get maximum value of A, B, and C, then I would write like: val = A; val = max(val, B); val = max(val, C); But, in this case, I need to write two "val" in the one line. And, it is ...
1
vote
1answer
59 views

skipping comment line from keyboard (stdin)

I have to write a code in c++ where the requirement is to skip a line beginning from '#' sign. So basically we need to treat it as a comment line. The input is given by the user from the keyboard. I ...
-1
votes
0answers
23 views

Trying to make siri applicaton in xcode using OpenEars [closed]

There I have made an application like sir where it asks you what it would like to search for then searches for it but i want to add.... when the person says hello then program responds how are you ...
2
votes
0answers
92 views

Immutable C++ stack - thoughts && performance

What are your thoughts on the fallowing immutable stack implementation ? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
1
vote
1answer
32 views

OpenGL abstraction layer

I tried to create a small OpenGL abstraction layer. I am an unexperienced programmer and I am relatively new to c++. I tried to favor composition over inheritance but somehow it added extra ...
1
vote
1answer
33 views

Creating custom random access iterator in C++ 2011

I would like an opinion on my code. I need a random access iterator for my custom container. If I read the C++ 2011 standard, specially chapter 24, I understood that an implementation could be the ...
-1
votes
0answers
32 views

Operator Overloading [closed]

I'm trying to write a code that returns 1s and 0s instead of true or false. But this doesn't seem to be right. int Short_Vector::operator==(const Short_Vector& obj){ if(a == obj.a && ...
2
votes
1answer
83 views

Greatest prime number smaller than N where N can be as large as 10^18?

This is code for finding largest prime number smaller than N where N can be as large as 10^18. But it takes 1 minute for 10^18 . I need to pass it in 2-3 sec. What changes should I make to pass it. ...
0
votes
0answers
36 views

HashSet add and search functions

This is my first time implementing a hash set and I need your help. I know I didn't implemenet the operator= and the copy constructor(that's because I don't know how to), and the remove function. I ...
4
votes
2answers
129 views

HashTable - separate chaining collision in C++

guys! This is my first time here, and the first time I'm trying to implement a HashTable. In fact, I want a HashSet with Persons that have a name and a phoneNumber, both string. I understood the ...
2
votes
1answer
68 views

Can I make a regex array to iterate through in C++?

I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this: regex regex_a (".."); string rewrite_a = "($1/$2)"; regex regex_b (".."); ...
-1
votes
0answers
25 views

C++: Vector implementation copy constructor error [closed]

I'm trying to implement a version of vector (for learning purposes). My code fails to create second vector with copy constructor raising SIGABRT in insert() function. Still can't find my mistake. Any ...
2
votes
0answers
109 views

Best practice and/or cleaning binary/decimal/octal/hex converter (now for floating-point values)

This new code comes from my original converter (without floating-point support): Cleaner and/or more practical code for decimal/binary/hex converter I've had some trouble implementing floating-point ...
3
votes
1answer
46 views

Selecting element from a collection based on bitwise-and result

I need to improve this section of code: uint32_t to_handle = 0; uint32_t test_const1 = Constraint3::VAL1 + Constraint3::VAL2; uint32_t test_const2 = Constraint1::VAL2 + ...
1
vote
0answers
33 views

Design issue with decoder class

I'm designing a C++ Decoder class for decoding a format, and would like some feedback on my design choice: I want the user to be able to provide input to the decoder by either supplying an array, a ...
1
vote
1answer
81 views

How do I design this code better?

ALL, I am developing a program that uses GUI and SQLITE. For the GUI I use wxWidgets and use SQLITE API directly. Right now I have a main frame class CFrame and database class CDb. The CDb class ...
1
vote
1answer
56 views

std::string/std::wstring template wrapper for Win32 API

I have not completed this but want to make my own template library for wrapping the Win32 API to make it compatible with std::string/std::wstring... Here's a sample of what I've worked with so far. ...
5
votes
1answer
220 views

Code Review for Hangman in C++

I have the following C++ program: #include <iostream> #include <cstdlib> #include <ctime> #include <vector> void printVector (std::vector<int>& vec) { for (int ...
1
vote
1answer
57 views

Simplify bit flags checking code

Please help make this code more cleaner. It's a part of window procedure that notifies my renderer before client area of window resized. I need to check two combinations of bit blags: some of them ...
-1
votes
0answers
33 views

C++/Math - Camera class has max height climb issue [closed]

For some reason, there seems to be a limit to the height my camera can climb. It seems that no matter the pitch, it doesn't go directly the direction the camera is facing. If I am at say 75 degrees it ...
2
votes
3answers
141 views

Cleaner and/or more practical code for decimal/binary/hex converter

I've finally finished my converter and have determined that it works, but I'm trying to make it cleaner and/or more practical (primarily with the switch statements). I could probably put more things ...
-1
votes
0answers
31 views

Array sorting code and file IO [closed]

I would appreciate if someone could help me finalise a code. I need to read in people's info (such as ID, age, etc.) from a text file into different arrays. Records are like this 2012317109 Jamie ...
0
votes
4answers
83 views

c++ concurrent queue with pthread implementation

I'm writing a multi-threaded queue implemented with pthread. Since I came up with the code based on several tutorials from Internet, I would like to make sure there is no logic error in my code: ...
4
votes
3answers
116 views

All integer sequences given amount of integers and length of sequence

Given two integers, X and Y, you must create all possible integer sequences of length Y using the numbers from 1 to X. For certain reasons, the function must return a deque<deque<int> > ...
3
votes
1answer
55 views

Console menu, input stream - keeping clean code

I've written simple numeric menu which displays in the console. When user clicks '1', something happens, then when he clicks enter, I clear the whole output except for the menu itself. When the user ...
4
votes
4answers
132 views

General advice on a practice linked_list for C++ classes/templates

Introduction I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this ...
3
votes
1answer
62 views

Thread-Safe Game Engine: Multi-Threading Best Practices?

I'm writing a multithreaded game engine, and I'm wondering about best practices around waiting for threads. It occurs to me that there could be much better options out there than what I've ...
0
votes
0answers
30 views

Understanding macro cpp coding practice [closed]

I am trying to understand the following code: http://pastebin.com/zTHUrmyx I have compiled the code and am trying to use gdb to step through the code. Specifically, I'm trying to understand EXECUTE ...
3
votes
4answers
107 views

Request for review: reference counting smart pointer

I made a reference counting smart pointer class. My aim is to make a "minimal" but "general purpose" smart pointer class with proper documentation. This is basically for educational purpose. Please ...
0
votes
3answers
60 views

Input reading: two values (separated by whitespace) per line

Sometimes, I need to read two integer parameters in a single input line, separated by a whitespace. I have these two functions that seem to do the job just fine: #include <iostream> #include ...
3
votes
1answer
59 views

Largest sequence found in all strings

**Note: I might put this on Code Golf too, but first I'd like to get this code reviewed. So there's this programming contest my school will be holding soon, which is about solving problems in the ...
0
votes
0answers
15 views

D3D COM Object Pooling

I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe? CComPtr<ID3D11Texture2D> create_texture(const ...
0
votes
2answers
64 views

JSON API in C++ with Node.native, RapidJSON, and MySQL

Hey folks, I was hoping I might get some feedback and ideas for improvement on this, particularly the WebRouter class. Any tips or suggestions would be great! #include <native/native.h> ...
3
votes
2answers
162 views

Singly linked list for review c++

#include <iostream> using namespace std; struct node_ll { int payload; node_ll* next;//Pointer to the next node }; void print_ll (node_ll** list) { node_ll* temp = *list;//Let temp ...
1
vote
1answer
110 views

Guess my Number in C++

I have recently created my first game in C++: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { cout<<"\tWelcome to Guess my ...
0
votes
0answers
70 views

Hanoi Towers - need help with the code

I made an algorithm solving Hanoi Tower puzzles, for n disks and m pegs. It uses lists as pegs, each list's element contains disks array - {0, 0, 0} means the peg is empty, {1, 2, 0} means the peg ...
0
votes
0answers
21 views

Can this function (implementing HTUnEscape) be optimized?

Came across the following piece of code in an UI application I need to maintain. int tool_unhex( char c ) { return( c >= '0' && c <= '9' ? c - '0' : c >= 'A' && ...
1
vote
0answers
60 views

(Suggestions) RISK-like game in Qt

Description I am working on a game similar to RISK, and I am wondering about the best way of manipulating the territories (both the user and the program). Firstly, I am looking for a way to select ...
-1
votes
1answer
34 views

C++: Last digit of an exponent of number - wrong answer [closed]

I'm trying to implement a simple program that takes base and exponent and output the last digit of a result of exponentiation, but online judge says that my program gives wrong answers. What could be ...
1
vote
1answer
63 views

How to simplify code for display member functions?

For my display functions in my Blackjack game, I want to control each player's stats output based on whether a turn is in progress or has ended. Normally, you could only see one card that your ...
2
votes
1answer
130 views

Is this implementation of Kruskal's algorithm maintainable and efficient?

Update I've posted some updated code and included the definition of Vertex and Edge to try to answer as many questions as I could. To summarize what's changed: I've followed the advice here to ...
1
vote
1answer
40 views

Possible “shortcut” for accessing multiple data members?

In my Blackjack game so far, I have multiple classes that access each other frequently. For example, this is my hit() function for the Game class: void Game::hit(unsigned playerNum) { Card ...
0
votes
2answers
96 views

C++: Prime Number Generator algorithm optimization

I've implemented a simple program that finds all prime numbers between two integer inputs using Sieve of Eratosthenes, but online judge is still complaining that time limit is exceeding. Maybe I'm ...

1 2 3 4 5 14