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

learn more… | top users | synonyms

-2
votes
3answers
249 views

Programming in Linux (C++) [closed]

So I don't know If this is the right place to ask this. I am new to programming, I am not very in to it (I know classes,arrays,functions..etc(Basic Things)). I was programming with Visual Studio 2013 ...
15
votes
4answers
2k views

Why aren't `void *`'s implicitly cast in C++?

In C, there is no need to cast a void * to any other pointer type, it is always safely promoted. However, in C++, this is not the case. E.g., int *a = malloc(sizeof(int)); works in C, but not in ...
-3
votes
1answer
141 views

Physics/Game Engine in C++ for mobile app [closed]

First post so be gentle. I am a junior seeking a Comp Sci major and was looking into making a mobile game. I wanted to use this for my thesis project next year, and possibly a way to pay back college ...
1
vote
1answer
101 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 ...
-2
votes
1answer
97 views

Is visual c++ cross plat [closed]

Is VC++ cross platform? If, not how can i make it. Should I just use code blocks for cross platform and include any needed dlls in the project? I'm using OpenGL and need to make my game supported for ...
0
votes
1answer
123 views

How can frond-end developer support different encoding (UTF-8 , UTF-16,..)other than ASCII? [closed]

I'm writing simple language compiler frond-end (based on LLVM) in C++, and I wonder how could language support encoding stuff? How can I (as compiler writer) support encoding? I need to know the ...
3
votes
1answer
321 views

raw, weak_ptr, unique_ptr, shared_ptr etc… how to choose them wisely

There is a lot of pointers in C++ but to be honest in 5 years or so in c++ programmation (specifically with the Qt Framework) I only use the old raw pointer : SomeKindOfObject *someKindOfObject = ...
0
votes
1answer
77 views

Adding permanent objects to a vector

I'm relatively new to C++ (coming from Java) and I've got a little problem regarding lifetime of objects. My situation is like this: I'm having a class A in which I'm trying to add elements to an ...
1
vote
1answer
119 views

Polymorphism Question

For the sake of the question I've taken this code from http://www.cplusplus.com/doc/tutorial/polymorphism/ class Polygon { protected: int width, height; public: void set_values (int a, ...
1
vote
3answers
126 views

Protect memory from a potentially seg faulting function call

How can one safely call a function that might segfault without corrupting the stack or the heap? These SO questions cover using signal handlers and setjmp.h to regain control. Coming back to life ...
1
vote
1answer
135 views

How to make sure that the destructor cannot throw an exception?

I know that we can specify the compiler that a function is not throwing an exception by using noexcept specifier but noxecept functions can still throw exceptions . So, how to prevent destructor from ...
1
vote
1answer
196 views

How to avoid violating one definition rule in this case?

We have an existing Mutex C++ class. It has a debug feature to track the owner thread id. So it has a member variable to store this, but because the original developer doesn't want to waste memory, ...
4
votes
2answers
374 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 ...
2
votes
2answers
93 views

Free Standing Functions in Global Namespace

When writing non-member, free functions, can they be placed in the global namespace so long as the signature specifies a namespace-scoped object? For example, in the code below, is "Example 2" ...
4
votes
1answer
115 views

Convince Windows SmartScreen and web browser that my application is safe?

I am developing a Free and Open-Source software (C++). When I download my own application from a web link, Microsoft Smart Screen and Google Chrome are getting in the way since it comes from and ...
2
votes
2answers
99 views

Typedefs to convey relations between classes

I'm wondering if the following use of typedefs is any good practice, or if there are any downsides to it. Basically I have alot of "data"-structs, which are intended to be used in (globally unique) ...
3
votes
2answers
234 views

How to iterate through all permutations of valid links between nodes

Imagine a 2D area, with a number (array) of nodes (or points) defined within it, in arbitrary (but known) positions (integer x,y coordinates), like this: From there I want to be able to, ...
1
vote
2answers
86 views

Logging function names on systems with few (memory and space) resources

Our logging module has a buffer that often gets full and we are searching for a solution to shorten our logs, without making any compormise in performance. The code is written in C++ and currently we ...
0
votes
5answers
533 views

Is a makefile really needed

I have been programming in c/c++ for a while now, and I have never once used a makefile. I know that it is supposed to be useful when you are dealing with a large project, but I have always been able ...
0
votes
0answers
82 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 ...
0
votes
1answer
55 views

Perrin sequence help c++

Hey everyone I am trying to write a recursive function for a perrin sequence where it returns the nth term that a user enters which is: P(0) = 3, P(1) = 0, P(2) = 2, and P(n) = P(n − 2) + P(n − 3) ...
58
votes
11answers
8k views

Why is base-for-all-objects discouraged in C++

Stroustrup says "Don’t immediately invent a unique base for all of your classes (an Object class). Typically, you can do better without it for many/most classes." (The C++ Programming Language Fourth ...
3
votes
2answers
712 views

How do you usually compile C/C++ source code ? (Large code bases) [closed]

It's been quite some times since I began learning C and C++ but I've been very limited only to the Windows platform and the Visual Studio environment. Recently, I wanted to look into some open source ...
3
votes
1answer
156 views

How can I use the “Non-Member Functions Improve Encapsulation” pattern from C#?

In 2000, Scott Meyers argued that non-member functions improve encapsulation. In C++, a non-member function is a C-style global function: ...
0
votes
1answer
104 views

C++ Templates where the type is a shared_ptr

When creating template classes in C++, if the type upon which the template will be specialized is intended to be a shared_ptr type, is it better to make T a shared_ptr type or make T a non-pointer ...
0
votes
2answers
109 views

Organizing C++ Components [closed]

In my current company we've brought the discussion about how to organize most of our different C++ components considering the following requirements: There might be interdependencies between ...
2
votes
1answer
195 views

An embedded C developer wishing to interface some code with a web page

Okay, so as the title says, I'm an embedded C/C++ developer. Right now, I'm working on a project that involves a client/server C application. The server side of the application is running on ...
-1
votes
5answers
2k views

Why Java is a factor 2-3 slower than equivalent C++ program? [closed]

I know there is an opinion that programs written in Java and running under JVM as as fast as C++ programs, after introducing just-in-time (JIT). I see many cases when Java is terribly slow for simple ...
0
votes
1answer
109 views

Is it not direct usage of primitive pointer types form of Primitive Obsession?

Using primitive data types to represent domain ideas is code smell called Primitive Obsession. For example using string data type to represent human name - it is recomended to avoid this by defining ...
1
vote
1answer
70 views

Should factory make context or concrete strategies objects in strategy-factory pattern?

In a typical strategy pattern class Strategy { public: virtual int execute() const = 0; } class StrategyA : public Strategy { public: int execute() const override; } class StrategyB : ...
2
votes
1answer
194 views

Well defined mathematical operations for bearing (angle) class

I have written a class to represent bearings (angles with a nautical theme, and a specific normalisation range). In the program, it is necessary to perform some mathematical operations on them, so ...
1
vote
0answers
126 views

General design choices. How do you decide?

I have a project in C that I'm looking to convert to C++. The project does white box hardware testing of a device (actually many similar devices). In this case the device has two processors. Each ...
2
votes
1answer
307 views

Tips for understanding big project fast? [duplicate]

I've got a job and many new things to be learned. The first thing is to understand big project, writtened mostly in C++, using Visual Studio. So, I see a statement, and I want to find its definition. ...
0
votes
1answer
118 views

How shall I handle event loop exceptions?

What is the best practice for handling exceptions thrown from event handlers/listeners in a event loop? For example: class EventLoop { public: void start(); //create a thread which calls run(); ...
1
vote
1answer
189 views

Why does this algorithm work in O(n m)?

This is from a blog post on Codeforces. I couldn't really understand why the editorialist goes on to claim that this code works in O(n m) This is a graph problem, where we are supposed to find the ...
1
vote
2answers
176 views

Why does this implementation of Dijkstra's algorithm work in O(n^2)?

Here is the code I use for implementing Dijkstra's algorithm. Consider a graph with n vertices and m edges. Shouldn't it run in O(n^2 m) ? Someone may say that there are n vertices and each edge gets ...
-3
votes
1answer
251 views

If-else in C++ Programming Language [closed]

I am a little bit confused about this code. Why does the else block get executed? Please explain it. int a=10,b=20; char x=1,y=0; if(a,b,x,y){ cout << "A" << endl; }else{ cout ...
1
vote
1answer
182 views

Using streams to connect programming languages

I'm trying to run a computation-heavy program that creates an image on a website. Is it possible to compute in C++ and have an output stream that connects to an input stream in Node.js to display an ...
1
vote
0answers
61 views

Maximizing reuse out of a function primitive in CUDA

I'm working on the implementation of a few related algorithms in CUDA, all of which require a primitive that we'll call f(). The related algorithms can't simply call f though, as they require f to ...
2
votes
1answer
196 views

Genetic Algorithm's Tournament Selection limit to be selected

I started working again on a Genetic Algorithm and i'm trying a lot of operators and ways of selection. When I made the Tournament Selection , I noticed that it gets really easy to always get the top ...
2
votes
1answer
188 views

Insertion sorting Algorithm comparison

I recently came across sorting techniques and of particular, 'insertion sorting'. Although the logic and method is fairly understandable, the actual function seemed a bit complex (given below). ...
1
vote
1answer
157 views

C++ Template Metaprogramming and Call By Need Evaluation

I recently wrote a fairly complex C++ meta function that boils down to: template <size_t N, typename val> struct Rec { using type = typename std::conditional<N == 0, val, ...
3
votes
3answers
485 views

Should I try it straight or should I first check if it can be done?

I have a set of items, and each item in the set must be unique. Item are composed from multiple properties and each property of each item can be changed. But after each change every item in the set ...
4
votes
1answer
296 views

What is the status of @ and $ characters in C++?

C++ syntax uses almost all printable ASCII characters and some of them in several contexts. Only two unused are @ and $ characters. Why they are not used? Are they reserved for some "meta" purpose?
3
votes
4answers
437 views

Are `switch` statements generally used wrong? [closed]

I see most developers using switch statements with breaks in each and every case. Is this usage of switch statements inappropriate since a simple set of if-else statements would suffice? Is it OK for ...
3
votes
0answers
230 views

How do you pronounce 'char' keyword? [closed]

So, with the possibility of this question being closed due to being non-productive as in the case of other pronunciation questions, I take the risk and ask it just because i have heard it said both ...
1
vote
2answers
107 views

Class as resource handle & Bad Copy

I am reading Bjarne Stroustrup's book titled "A tour of C++". The following section is confusing to me: When a class is a resource handle – that is, when the class is responsible for an object ...
-1
votes
1answer
77 views

What are some hashmaps we can easily implement? [duplicate]

At many places, I read that we can use HashMap here for O(1) search. Actually, I want to ask how I can implement easy hashmaps which can satisfy this property. Can anyone tell few hashmaps including ...
1
vote
1answer
140 views

Constructor vs casting operator

I'm programming a library (so I have complete access to all the mentioned classes). Two classes (A and B) are essentially the same and differ only by their implementation, so they can be easily ...
4
votes
1answer
177 views

Designing interfaces to hardware

I am writing a library in C++ that is used by customers to interface with hardware. There are many different devices that I need to support. For the sake of simplicity, assume I have 2 Widgets, ...