The tag has no wiki summary.

learn more… | top users | synonyms (1)

0
votes
0answers
5 views

Undefined reference error [migrated]

I know that there are a lot of questions about undefined reference out there, but I couldn't find any that is like my case, probably because I am new to C++. I am developing a little project ...
1
vote
2answers
119 views

Is returning a reference to inside a private vector bad practice?

I have the following trimmed class: #include <vector> #include "Tile.h" class Board { std::vector<Tile> boardArr; // VVV Bad Practice? Safe? Tile& getTileAt(unsigned ...
1
vote
1answer
136 views

Are there real world examples demonstrating reasonable performance improvement by using move semantics?

(I've asked a similar question on SO but unfortunately it might not be proper, so I also put here; please kindly point out if you think it's a duplicate.) I've heard many words about the move ...
0
votes
1answer
117 views

Moving from C++ to NodeJS - Working with XML and JSON

I need to make a program to compare several large +100MB XML files, find the difference, and spit out JSON. I have written the comparison code in C++ and it performs great but now when I am getting to ...
1
vote
1answer
80 views

Run a c++ program under lots of different data maps

I want to run a c++ program to process a lot of data from different xml files and output results. I run the program once per file and potentially have around 50 different files. The trouble is each ...
-1
votes
1answer
110 views

Why does C++11 developers prefer space before colon in range-based for loops? [closed]

In most of the C++11 codes, I see: for (auto i : list) { // a space before colon ... } However, usually C++ developers do not prefer: for (int i = 0 ; i < list.size() ; ++i) { // spaces ...
1
vote
1answer
74 views

Calculating the determinant of a matrix

I am working on a library (in my spare time) that I hope to open source soon. One of the elements in the library is a method for calculating the determinant of a given input matrix. For this, I have ...
0
votes
1answer
122 views

Best algorithm for “ACM ICPC Team”

I have this problem (complete description): There is a list of persons N and M topics. I have to find out the maximum number of topics a 2-person team can know. And also find out how many teams can ...
1
vote
1answer
107 views

Avoiding std::forward and Rvalue References

I recently read the Google C++ Style Guide and especially one part catched my eye. The part about Rvalue References discourages from using std::forward in general and using rvalue references in other ...
4
votes
2answers
418 views

Const means Thread-safe?

I was put onto this video: http://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank By http://codereview.stackexchange.com/users/39810/glampert Because I asked ...
1
vote
2answers
143 views

c++11 random: why different range of int and real?

In the c++11, we now have <random> to produce random number. About uniform distributions, we have following int_distribution and double_distribution: uniform_int_distribution-produces integer ...
0
votes
0answers
88 views

Polymorphic template container: shared_ptr vs reference_wrapper

Assuming we have two classes: class A { ... } class B : public A { ... } Would it be better to write std::deque<shared_ptr<A> > container; or ...
1
vote
2answers
196 views

operator“” in modern C++

I took an example I found on-line whereby a constexpr of the form _binary could be evaluated at compile time as an unsigned long long and then I tried to generalize it for any base from 2 to 36. For ...
2
votes
1answer
99 views

When to use nested classes and when to use namespaces?

I have really never made use of namespaces, and am considering them at the moment. My situation. I have a class Reverb. It contains as members instances of other classes, declared in the same header ...
0
votes
2answers
67 views

Is it bad form to break out of Range-based for

I have a range-based for that operates over a std::vector of objects (items), like so: for(auto item : itemCollection) { if(!item.some_check(...)) { // do 5% stuff break; } ...
12
votes
2answers
2k views

Is this a good pattern: replacing a long function with a series of lambdas?

I recently run into the following situation. class A{ public: void calculate(T inputs); } Firstly, A represents an object in the physical world, which is a strong argument for not splitting the ...
3
votes
2answers
151 views

Will destructing a large list overflow my stack?

Consider the following singly linked list implementation: struct node { std::unique_ptr<node> next; ComplicatedDestructorClass data; } Now, suppose I stop using some ...
2
votes
1answer
97 views

Should a lockfree queue use a condition variable?

Suppose I have a lockfree queue in a multithreaded setting. I already provide a try_dequeue() method which allows for an optional failure (communicated via the return type) if the queue is empty. ...
3
votes
2answers
184 views

How to deal with historic exception specifications in maintained C++ code

Today, I discovered a few exception specifications in legacy code I've to maintain, when Cppcheck 1.68 ([Inconclusive] but correctly) pointed out that the specified exceptions are not handled in ...
2
votes
1answer
109 views

How to make max-heap stable with counter and account for counter overflow?

Generally I need size-efficient data structure similar to std::priority_queue but stable (preserving order of insertion). By adding just 4 bytes to the object I could have 1 byte serving as priority ...
2
votes
5answers
687 views

Why lambda/closures expressions came so late to C++?

I was reading a really great Bjarne Stroustrup's article where he exposes some C++ myths. I look at code that focus my attention, because I wouldn't know that C++ supports this kind of expressions. ...
7
votes
1answer
224 views

Message Queue for RTOS for microcontrollers

I'm currently writing an RTOS for microcontrollers. The whole thing is written in C++11 - if anyone is interested, and the link to the repository is at the bottom. Currently I'm writing a class that ...
4
votes
1answer
162 views

Too many parameters to data processing class constructor

I have a conceptually simple application: data comes in as small encrypted packets, they decrypted and validated, some are stored in the database, some rules are applied, and a reply might be ...
12
votes
2answers
653 views

Who is to blame for this range based for over a reference to temporary?

The following code looks rather harmless on first sight. A user uses the function bar() to interact with some library functionality. (This may have even worked for a long time since bar() returned a ...
4
votes
1answer
796 views

Move semantics in C++ - Move-return of local variables

My understanding is that in C++11, when you return a local variable from a function by value, the compiler is allowed to treat that variable as an r-value reference and 'move' it out of the function ...
3
votes
6answers
1k views

Unit test private method in c++ using a friend class

I know that this is a debated practice, but let's suppose that this is the best option for me. I am wondering about what is the actual technique to do this. The approach that I see is this: 1) Make a ...
-1
votes
2answers
163 views

Comparing doubles [duplicate]

I need to compare to double variables like this if (distance <= radius) both distance and radius are doubles and I remember in class how to use epsilon comparisons for checking equality but how ...
0
votes
1answer
46 views

confusion regarding handling of new smart pointers on stack frames?

Let me try to elaborate it. Stack Frame: When we execute any function it create stack where all local variables and instructions reside. And Smart Pointer: smart pointer like std::unique_ptr allows ...
2
votes
3answers
680 views

C++: Metaprogramming with a compiler API rather than with C++ features

This started out as a SO question but I realized that it is quite unconventional and based on the actual description on the websites, it might be better suited to programmers.se since the question has ...
-3
votes
2answers
215 views

Why friend in C++ should be in the header file? [closed]

Friend function/class, FriendOfX for some arbitrary class X is an implementation detail of class X. Why in C++ we have to declare them in the header file? Are there any compelling reasons to make this ...
1
vote
2answers
200 views

Is it an anti-pattern to use void* and enums to enable type-checking?

Say in a game engine, you have Objects that composited of different components. One of these is a RenderComponent which can be either a Mesh, a Sprite or a Light. Now, all these are vastly different ...
0
votes
1answer
99 views

In C++11 can Auto be used to get around mis-casting of void * parameters in functions?

If I have a generic function that takes a void* as a parameter, can Auto in C++11 help stop any bad casting of that parameter? For instance, we may have an event system that sends events and a ...
0
votes
0answers
26 views

Using rvalue references to signal function behaviour [duplicate]

I have been using functions accepting rvalue ref signatures to make explicit at call site that the object passed in effectively ceases to exist. This ensures that I don't mistake this function for one ...
0
votes
4answers
207 views

Cross Platform Compilation of C++ .exe

I have been asked to re-write an old C/C++ project in C++11. The old project is multi-platform, however, in order to deploy the system on other architectures the current process is to log into a ...
1
vote
2answers
171 views

The destination of cout messages in a GUI program

I've been building some classes and functions in a static library which has the familiar printing of text messages to stdout: cout << "Hello World!" << endl; I've been developing this ...
2
votes
1answer
79 views

How to define different names for the same type and have the compiler check them? [duplicate]

I would like to define several names for the same type and have the compiler distinguish between them. My motivation is that different int variables could represent very different units, and I would ...
2
votes
1answer
225 views

High-level description of how experimental C++ features are developed?

Herb Sutter in a video answers a question about the concepts proposal considered for C++11 and from his remarks it sounds like multiple groups offered prototype implementations but all of them left ...
22
votes
3answers
3k views

C++ strongly typed typedef

I've been trying to think of a way of declaring strongly typed typedefs, to catch a certain class of bugs in the compilation stage. It's often the case that I'll typedef an int into several types of ...
3
votes
1answer
409 views

How to maintain encapsulation with composition in C++?

I am designing a class Master that is composed from multiple other classes, A, Base, C and D. These four classes have absolutely no use outside of Master and are meant to split up its functionality ...
5
votes
2answers
1k views

Should I feel “uncomfortable” using auto in C++? [duplicate]

C++11 features the new auto type declaration, allowing you to work with an object without ever knowing its actual type. I use only strongly typed languages - C++, Delphi (Object Pascal), Go, etc and ...
0
votes
3answers
526 views

Why std::allocators are not that popular? [closed]

With the latest trends about C and C++ applications, and with latest I mean the latest years, I was expecting to see std::allocators to be used way more frequently than what it really is. Modern ...
1
vote
1answer
174 views

heading in right direction? C++ and class templates

I'm working on some inherited code in C++ and am trying to use 2 classes with templates as I need 2-types of each class to operate on floating point or integer data (double v uint64_t to be exact). ...
1
vote
1answer
339 views

Binary Tree/Knowledge Base design C++

Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main ...
4
votes
3answers
1k views

What are my options for using a C++11 library in a C# WPF application? [closed]

I am writing a cross-platform (OS X and Windows) desktop application in C++11. I intend to use the same C++11 core on both platforms, utilizing native frameworks for the UI (Cocoa and Objective-C on ...
1
vote
3answers
358 views

C API in C++ with RAII, two alternatives to implement error handling (Exceptions)

I have an API written in C, which produces a result by returning a pointer to allocated memory. For using it with C++ (C++11) I've wrapped the function calls in objects, which keep the result in a ...
2
votes
3answers
362 views

Why are pointers to literals not possible?

Reference to a literal is possible only if the reference is declared as constant. But why is a pointer to a const object not possible in case of literals? i.e. int const& ref = 5;// But why ...
1
vote
1answer
98 views

argument grouping with parenthesis are valid in C++?

On python I can group arguments into a tuple, something like def func((a, b, c, d), x): print a, b, c, d, x I was wondering if it is possible to group arguments in the same way on C++, ...
10
votes
3answers
3k views

Style guide for C++

Right now I am using Google C++ Style Guide in my C++ code and I was pretty happy with it. Recently I was told that this guide is very bad: it is used internally by Google (I knew that), is outdated, ...
0
votes
0answers
88 views

why c++11 define closure as a process of capturing variables

when using closure in other languages, it just feels nature, variables from outer scope are captured automatically , without the need of declaring such captures. in c++11, good to see we have ...
1
vote
2answers
394 views

Documenting the effect of std::move

As my team move towards embracing the new features in C++11 I'm struggling with how to make the side-effects of std::move self-documenting in the code. The issue is that an object that has been moved ...