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

learn more… | top users | synonyms

2
votes
2answers
209 views

Should C++ fields be pointers or objects?

I'm wondering whether it is better to make object fields within a class objects or pointers. Specifically it seems that using an object field requires the entire header for that object's class to be ...
2
votes
2answers
88 views

Stripping specified character

Here's some code that removes the specified character, ch, from the string passed in. Is there a better way to do this? Specifically, one that's more efficient and/or portable? //returns string ...
1
vote
1answer
2k views

Playfair Cipher Code Review C++

I have been working on a Playfair Cipher in C++ for a final Project in a Cryptography class. I was hoping for some feedback on the project so far. I Recently got a job programming before I've even ...
0
votes
2answers
155 views

Review C++ RPN Evaluator

So for Homework I had to write an RPN Evaluator and write the results to a text file. I've done all that - fine and dandy but it feels weird. Like the writing to my results text file. It doesn't feel ...
1
vote
2answers
438 views

Ordered Doubly Linked List Insertion

I'm working on a school project right now. It's an ordered(ascending) doubly linked list. I just wrote the Insert operation on it but I feel like the way I wrote it isn't that great. void ...
0
votes
1answer
81 views

Can you guys help me to improve this Arduino code for animatronic hand? [closed]

I am making a animatronic hand that is powered by two Arduinos connected via XBee radio's. I am very new to coding and this is my first attempt. I was wondering if you guys could help me a little as ...
2
votes
0answers
85 views

2 Gig Log Writter — Code Review

This is a log file writer that appends binary data to an existing or non existing log file. It will only write to a file up to 2 gigs. Upon exceeding 2 gigs it would open another log file by simply ...
2
votes
0answers
71 views

Template parameter used for configuration of classes

My question is design related. I am not sure if this good programming. I am not the well template programmer... I have 2 Questions at the end: I have a big simulation framework (rigid body ...
4
votes
1answer
124 views

Setting output width with ostream_iterator

I'd like to display a vector (implemented in my custom Vector class) and have the output width of the elements be configurable. I've done this by creating a simple wrapper for the element being ...
-1
votes
1answer
146 views

How to assign values to 2 dimensional array in c++ [closed]

I want to assign the result of this code into a 2D array, I tried to save the result from the first output of the program in a file, and later on I will re open the file to assign the values in to the ...
5
votes
1answer
702 views

I’m new to C++ and unsure about how to improve this code

The purpose of the following code is to get a random number of 100 nodes and to distribute these nodes randomly in range 500*500 …(X,Y).. this was the first step #include<iostream> #include ...
1
vote
0answers
104 views

Correct Use of Boost Mutex

I have an event driven system that needs the ability to turn on and off a logger. The issues is that the user could spam a button which could try to turn on the logger over and over again. The turning ...
0
votes
0answers
69 views

Which of ways to construct object is better?

Object, which is going to be constructed, has several constant. What of ways to place constants is better and why? The first way is function for each member: BarcodeObject::BarcodeObject() : ...
2
votes
1answer
200 views

Lexicographic rank of a string

Given a string, find its rank among all its permutations sorted lexicographically. For example, rank of “abc” is 1, rank of “acb” is 2, and rank of “cba” is 6. Assuming there is no duplicated ...
1
vote
1answer
386 views

Boost Threads - Producer Consumer threads with synchronization - Review

I have below code for multi threaded consumer and single producer. Kindly review it ro concurrency correctness. #include <iostream> #include <queue> #include "boost\thread.hpp" #include ...
2
votes
0answers
55 views

Can this token finding function be improved

I want to make sure find_value_from_key is safe and efficient. My constraints are language C++, use of standard library ok but cannot use boost or any new C++11 features. Can anyone offer any ...
3
votes
2answers
253 views

C++ and STL - Please Critique

I would like to get some general comments on style and use of STL in particular. This is some code I wrote to do machine learning classification (logistic regression). Any suggestions would be very ...
5
votes
3answers
532 views

Checking if two floating point numbers are equal

Is this the best way to check if two floating point numbers are equal, or close to being equal? template <class T> bool IsEqual(T rhs, T lhs) { T diff = std::abs(lhs - rhs); T epsilon ...
1
vote
0answers
135 views

Print all interleavings of given two strings

Given two strings str1 and str2, write a function that prints all interleavings of the given two strings. You may assume that all characters in both strings are different Example: Input: ...
2
votes
1answer
41 views

Better way to average around points

I have a chunk of code that averages around the points of a grid of values and Im trying to figure out if there is a better way to do the averaging. The array itself is 1 dimensional but i am using an ...
3
votes
1answer
139 views

Implementing C++ boolean function objects with logical operator combinations

I want to make a C++ object hierarchy of "classifiers", which can be composed together via logical operators into a single classifier that implements the whole logical combination. This is actually ...
1
vote
1answer
2k views

Implemenatation of Binary search Tree

Written a code to implement BST. I would like a code review and any suggestions to make it better? #include<iostream.h> #include<conio.h> #include<stack> #include<queue> ...
1
vote
1answer
275 views

Socket connect realization: gethostbyname or getnameinfo [closed]

for now I'm using: int connect(const String& address, int port) { struct sockaddr_in servAddr; struct hostent* host; /* Structure containing host information */ /* open ...
3
votes
0answers
85 views

OpenCV Mat processing time

I'd like to know whether having different variables for the src (source) and dst (destination) of an OpenCV function will have an effect on the processing time. I have two functions below that does ...
4
votes
0answers
509 views

Print all permutations with repetition of characters

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order Examples: Input: AB ...
3
votes
2answers
56 views

Which Casting Method Works Best

void Generic::IntToS16 (S16 & Out_, int & In_){ unsigned char * bytes_in = reinterpret_cast<unsigned char*> (&In_); unsigned char * bytes_out = reinterpret_cast<unsigned ...
1
vote
1answer
163 views

Ray-Triangle hit test [closed]

I'm trying to do a simple hit test on a triangle and return the first triangle hit. In my mesh class I have a public function which iterates through all the faces in the triangle, fetches their ...
1
vote
1answer
60 views

Checking if the entries of a map exist in another map

I need to check if a map is subset of another map. For this, I have written the following code: #include <string> #include <iostream> #include <map> using namespace std; /** * ...
1
vote
0answers
74 views

Is this the right way to handle game states?

I'm writing a ORPG. The code below is client side. I have main thread looping in Game::Run: Game::~Game() { PopAllStates(); } void Game::Run() { sf::Event Event; ...
2
votes
2answers
176 views

the number of connected component

Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, M(x1, y1) == -1 && M(x2, y2) == -1 && |x1-x2|+|y1-y2|=1 ...
3
votes
2answers
159 views

novice c++ programmer looking for advice

I have been programming in c++ for around a month now, just long enough i figure to develop bad habits. Can anyone point out where i'm making mistakes and topics i should investigate to understand ...
5
votes
2answers
704 views

reverse every word in a string(should handle space)

Examples: char test1[] = " "; char test2[] = " hello z"; char test3[] = "hello world "; char test4[] = "x y z "; Results: " " " olleh z" "olleh dlrow " "x ...
2
votes
1answer
153 views

Is there anything wrong with my self-implemented C++ exception class?

I wrote my own exception class, deriving from std::runtime_error to have Error-IDs, timestamps and inner exceptions. It seems to work, but are there any drawbacks? The only thing I see is the ...
5
votes
1answer
130 views

Improve my little syntactic hack

Current best practice for using a lock_guard looks like this: // introduce scope to take the lock { lock_guard lock(sync); // sync is an accessible mutex object do_protected_stuff(); ...
4
votes
1answer
162 views

Review my file-searching program

It's my first window program. It simply searches for a specified file in the whole computer. File Search.h (header file that contains the prototypes of fileSearcher class methods.) #ifndef UNICODE ...
2
votes
0answers
126 views

C++ SGI STL pop_heap() method's implementation can be improved like this?

Through the source code, I find SGI STL pop_heap() have three steps: put the root value into the last; percolate down; percolate up. so pop an element at least require logN(tree's height) swap. ...
6
votes
4answers
2k views

C++, simple function to determine the circumference and area of a circle

First off I would like to state that this is a homework assignment. However, I am not looking for you to complete anything for me. I code I am posting is the completed homework assignment. However, ...
2
votes
1answer
176 views

Polymorphic STL foreach without passing the container type

I was trying to figure out how to make a foreach macro for STL containers that is break-able and I came up with this method that uses templates to recognize the container type automatically. Any ...
4
votes
2answers
198 views

Efficient implementation of a Dynamic Programming problem

I wrote following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. I wonder how can I optimize this code more efficiently, especially the part of ...
2
votes
1answer
174 views

Arduino based SNES controller wireless transmitter/reciever, code questions

I am building a transmitter and reciever pair for two SNES controllers, as I don't like using long extension cords to get the controllers to reach the couch. I'm using atmega328p's for the avr's, ...
3
votes
0answers
85 views

UVA 10474 - Where is the Marble Timelimit

I got a problem from UVA online judge Problem link. I have read it tons of times and as they said, I have to get the answer really fast. I have used a binary search and STD::Sort, but I am still ...
2
votes
1answer
65 views

Is it safe to cast a pointer to non-void function into a pointer to void function?

I thought it was a good idea to use this in my C++ projects: class CRAIICall { public: typedef void (WINAPI * FnType)(HANDLE); CRAIICall(HANDLE h, FnType fun) : m_h(h), m_fun(fun) ...
0
votes
2answers
128 views

C++ counter part of Java's “package private”

I'm writing a C++ library which needs deeper access to its own classes than it wants to allow the application using the library to have. I'm talking about headers to be included by the application, ...
4
votes
2answers
139 views

Am I reconstructing the buffers correctly

I am writing a networked audio application that sends the audio in 320 byte chunks, later I need to provide the player a bigger amount of bytes to play so I try to merge 2 or more chunks into one ...
3
votes
2answers
893 views

Multithreaded Socket code to connect to 100 different machines

This is my socket.cpp #pragma hdrstop #include "MySocketClient.h" MySocketClient::MySocketClient() throw(SocketException){ WSAData data; InitializeCriticalSection(&sect_); ...
2
votes
3answers
132 views

Windows DLL Module Class

I am doing a project where I use DLL's as run-time modules or plugins. To do this, I use the Windows LoadLibrary() and FreeLibrary() API calls to call two functions exported by the DLL. I decided to ...
2
votes
1answer
67 views

Is this P/Invoke code standard?

I have two projects, a native C++ DLL (pinvokelib.dll), and a C# console application (pinvoketest.exe) which calls the DLL. I'm curious if the way I do P/Invoke is considered best practice. Here is ...
2
votes
1answer
138 views

Base64 encoder/decoder has minor offset error for image data [closed]

I've written a Base64 encoder/decoder. It works great for plain text. When I pass it a 24-bit .bmp it successfully and correctly encodes it, but when I attempt to decode it the file header comes back ...
4
votes
2answers
1k views

atomic_queue - thread-safe and lock-free implementation of the FIFO data structure pattern

please review my implementation of a FIFO data structure that guarantees thread-safe access without locking. I removed the license header block and all Doxygen comments. The original version (along ...
6
votes
1answer
317 views

Threading lambda functions

I've created this very small header that allows direct creation of threads from lambdas. I can't find anything else similar on the net so I want to know whether there are any problems with this that I ...

1 3 4 5 6 7 15