Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
4 votes
4 answers
657 views

Coding Practice - Float* -> Vector3* cast

If you were given the following: ...
hiddensunset4's user avatar
4 votes
1 answer
2k views

Small 3D and 4D vector utilities

I'm a hobby programmer and have started 2 month ago with C++. I had some knowledge of Python, and I learned it all through Internet tutorials. I'm looking for your help, since I don't have a tutor I ...
Pella86's user avatar
  • 557
7 votes
2 answers
769 views

C++ Class wrapper on top of WinMain/DllMain

I've written some code to do the job for me. The final results seems to work fine, but I would like to know if this is how I should Handle classes. And where I can improve or things which are just ...
NLScotty's user avatar
8 votes
4 answers
1k views

Prime generator

I'm coming from a Python background(look at indentation :) ) and trying to learn basics of C++. I wrote a simple prime generator, I know there is better algorithms, but I want advices about coding ...
Utku Demir's user avatar
6 votes
3 answers
1k views

Print pair representing objects from sequence of nonnegative integer pairs

There are some things I am not sure of from a professional standpoint about the "correct" way to write C++ code. I have been looking through source code produced by various opensource projects, as ...
Matthew Hoggan's user avatar
2 votes
1 answer
2k views

Slow mutable priority queue

I needed a mutable priority queue (the priorities can be changed) for my currect project, and started by simply wrapping a class around a std::vector and make/push/...
carlpett's user avatar
  • 163
4 votes
3 answers
2k views

Static class member destruction in C++

I have a basic cache set up. Whenever a user requests a bitmap, it fetches or loads it from disk if it isn't already loaded, significantly reducing load times. Currently, the design explicitly tells ...
Casey's user avatar
  • 748
4 votes
3 answers
600 views

Sprite and AnimatedSprite

I have a Sprite class and an AnimatedSprite subclass, and I'd like to decouple these them and maintain substitutability, ...
Casey's user avatar
  • 748
9 votes
3 answers
4k views

Use of nested namespaces in 3D graphics engine library

I know that nested namespaces are used in C++ very rarely. But I think it's a nice solution to exclude types from global scope and sometimes it helps to write programs faster when we use things like "...
shadeglare's user avatar
8 votes
9 answers
7k views

Simple chain reaction game

Not long ago I tried to get a game developer job (casual games). There was a task to write a simple game like this one. I was supposed to use an existing game engine (given in the task) and only ...
shadeglare's user avatar
5 votes
2 answers
381 views

depthFirstTraverse fully in C++?

Wondering if this is fully in C++, and if not can someone help me tell the differences. This was submitted by me last semester, and received a good grade. I'm currently trying to ensure I can tell C++ ...
FossilizedCarlos's user avatar
3 votes
7 answers
8k views

Prime number finder

There's another exercise from Thinking in C++. This time it asks this: Write a program that uses two nested for loops and the modulus operator (%) to detect and print prime numbers (integral ...
Overflowh's user avatar
  • 133
2 votes
1 answer
262 views

Which is the better way to return a new instance of a boost intrusive_ptr

Unlike most(?) smart pointers, boost::intrusive_ptr has a non-explicit constructor. Given that, one could write ...
SCFrench's user avatar
  • 131
4 votes
1 answer
2k views

Typesafety with dlsym function loading

Aim: Use C++0x features to make function interposition safer. The problem is that it's easy to make a typo when wrapping and interposing on functions. Prototype Implementation: ...
Flexo's user avatar
  • 440
6 votes
1 answer
1k views

Determine if an element exists in a sorted NxN matrix

The point of this algorithm is to see if an element exists in a NxN matrix that has its rows and columns sorted. What would you change? What did I do well? Both perspectives help so I am not left ...
Matthew Hoggan's user avatar
17 votes
4 answers
2k views

Recursive and iterative Euclidean algorithms

Is this code too cryptic? Simple yes or no question. Feedback is optional. ...
Matthew Hoggan's user avatar
7 votes
4 answers
8k views

Simple array implementation without bounds-checking

I am preparing myself for some job interviews. This is a simple array (with the error handling left out for brevity). Any input or suggestions on style and the use of templates would be appreciated. <...
Charles's user avatar
  • 73
4 votes
1 answer
760 views

More generic sorting algorithm: using namespaces

I am currently reading The C++ Programming Language (Special Edition) and am learning about using templates. One of the exercises asks you to program a generic version of quicksort. I am hoping to ...
Matthew Hoggan's user avatar
6 votes
2 answers
297 views

Determining which command line arguments are numeric

I am working on using STL and in general safe C++ practices. Instead of posting large samples of code I am working with a small sample to catch problems before I move onto larger ones. How do you ...
Matthew Hoggan's user avatar
5 votes
1 answer
126 views

Skip_over() algorithm

I'm just curious if this is clear to the average person. ...
Billy ONeal's user avatar
  • 1,470
5 votes
4 answers
753 views

My own quicksort algorithm

I will make it more reader friendly after I get the algorithm completed. Does anything with the quick sort algorithm stand out as for why it is not working 100%? This is not homework; I am just ...
Matthew Hoggan's user avatar
3 votes
3 answers
2k views

Compute and print the sum and mean of name and value pairs

I'm just looking for more feedback on style/approach regarding this small problem. Also, if you have tips to make it more readable or C++-like, please let me know. Also, why is the problem asking for ...
Matthew Hoggan's user avatar
8 votes
2 answers
2k views

BitTorrent peer protocol messages

I'm writing a BitTorrent client. Part of the protocol is an exchange of length-prefixed messages between peers. The forms of these messages are described in the official specification and also in the ...
R. Martinho Fernandes's user avatar
6 votes
4 answers
607 views

Compute random triplets of float pairs and average area of generated triangles

I am trying to get in a lot of practice for interviews so I am trying to write as much code as possible, and getting feed back from excellent programmers like "you". Can I get some general feed back ...
Matthew Hoggan's user avatar
2 votes
1 answer
549 views

Reading a sequence of points and finding the closest one to the first

I was told this is the place to come for input/feedback on your programming. I am always looking to improve either by personal review or outside opinion/help. Would the community here be willing to ...
Matthew Hoggan's user avatar
100 votes
16 answers
9k views

Outputting the names of cars, without repetitions, with the number of occurrences in order of decreasing repetitions

A short while ago, I have submitted a coding exercise to a potential employer. The response came back the next morning and you can guess what it was from the subject of this post. I am not ...
Jozin S Bazin's user avatar
1 vote
1 answer
571 views

VC++ Fast Http Download

I am a C# developer, dont know much about vc++ or c++, never used it, for some reasons i have decided to use a c++ dll in my app for downloading content from the web. I dont want to use WebClient. I ...
Milan Solanki's user avatar
4 votes
4 answers
869 views

Most elegant way to write this loop

I have some code which looks like this: ...
Felix Dombek's user avatar
  • 1,081
6 votes
4 answers
3k views

C++ enums - which one is better?

I have a large namespace, but I don't want enum constants to be a part of it. In cases where an enum is related with a class, I coded enums inside the class so I can reach it using the class name. ...
Cem Kalyoncu's user avatar
7 votes
2 answers
2k views

Lexer code in C++

I've got a lexer written in C++ (Visual Studio 2010, so including lambdas and a few other C++0x tricks). This is my first lexing experience, the only other source code interpretation I ever did was ...
DeadMG's user avatar
  • 849
2 votes
3 answers
139 views

Should I hide or show this implementation?

An animation is composed of frames. I have the following class: ...
Clash's user avatar
  • 135
3 votes
0 answers
1k views

Integrating SFML and Box2D lib, and a Mass Production Shape Factory [closed]

I've just written two new headers: one that integrates Box2D and SFML by a class called BodyRep which creates/ is a graphic representation of any body, and one that ...
Griffin's user avatar
  • 297
6 votes
2 answers
4k views

Finding the largest palindrome from the product of two n-digit numbers

The program finds the largest palindrome made from the product of two n-digit numbers, where n is specified by the user. The code included works, however, when the user enters 5 or greater, the ...
rrazd's user avatar
  • 173
6 votes
1 answer
331 views

Tree/array mashup

I'm currently trying to prove a data structure which I've created to speed up lookups for integral keys. The specific case I have in mind has the following usage case: At start is populated with n ...
Nim's user avatar
  • 460
9 votes
1 answer
6k views

Generic C++ Factory

For my project, I needed a way to instantiate different object types during runtime using "string names", for this I designed a generic factory that is created for each object hierarchy type (...
bcsanches's user avatar
  • 370
3 votes
2 answers
501 views

Iterating over unequal unordered pairs in one collection

This code kinda hurts my feelings -- everything else in my code is done in neat one-liners, exploiting algorithms and, sometimes boost::bind, except for this piece. ...
Kostya's user avatar
  • 133
8 votes
3 answers
2k views

Custom integer class for calculating crypto algorithms

How can I improve upon this integer class that I wrote? I am/will be using this for some calculation intensive crypto algorithms, mainly POLY1305AES. I might even write RSA using this. I know that ...
calccrypto's user avatar
5 votes
4 answers
481 views

Truthy assignments

I often argue with the voices about the correctness of having assignments within an if statement (or equivalent), meaning having this: ...
dukeofgaming's user avatar
10 votes
4 answers
748 views

Critique my first C++ "Hello World" program

This is my first attempt to write a simple C++ program: ...
nkint's user avatar
  • 518
8 votes
1 answer
579 views

Use of external memory or a custom allocator

I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a ...
0xbadf00d's user avatar
  • 300
6 votes
1 answer
2k views

Fixed point combinator in C++1x

This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation? PS. This implementation is fully lambda expression based. If I can make ...
Earth Engine's user avatar
2 votes
1 answer
3k views

How is my SFML sprite Move() function?

I'm making a pong game with SFML and in the process made a function that takes a Time, Speed, ...
Griffin's user avatar
  • 297
2 votes
3 answers
897 views

Finding social network of a friend

Following is the code which finds the social network of a friend (i.e. friends of friends and so on). Friends definition is, ff W1 is friend of W2, then there should be Levenshtein distance equal to 1....
Avinash's user avatar
  • 121
6 votes
2 answers
863 views

Bit-twiddling for a custom image format

The following code is mainly concerned with the conversion from byte/bit stream to numericals such as int, unsigned int, short int, unsigned short int, float, and etc. These functions are heavily used ...
GoldenLee's user avatar
27 votes
2 answers
3k views

C++ API for interfacing with Lua

I wanted a good way to move objects back and forth between Lua and C++, and I didn't want to use anything like LuaBind or the other available libraries I could find, so I instead wrote this. It's ...
Alex Ames's user avatar
  • 463
7 votes
3 answers
7k views

Sales tax calculator

Please review the sales tax problem which has been designed using strategy pattern. The Problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical ...
somenath mukhopadhyay's user avatar
3 votes
1 answer
650 views

Conditional parsing, non-standard approach

Conditional parsing (aka read some tokens and return true or false). As a solution to this SO question, I wrote following code: ...
rubenvb's user avatar
  • 190
5 votes
1 answer
1k views

An implementation of "finally" in C++0x

I've made a quick finally type in C++: ...
Jon Purdy's user avatar
  • 223
15 votes
3 answers
14k views

Simple text-to-binary converter written in C++

I am learning C++ on my own and was hoping for some feedback on this simple text-to-binary converter. The program runs and I haven't encountered any errors with it yet. Any input is welcome. ...
Guy's user avatar
  • 175
5 votes
2 answers
11k views

Decoding binary coded decimal (BCD) value

I have 3 questions, all of them are concerned with binary coded decimal (BCD) conversion. My coding snippets are listed as follows. But I don't like my algorithm because it takes too long when dealing ...
Golden Lee's user avatar