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

learn more… | top users | synonyms

0
votes
0answers
11 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 ...
0
votes
0answers
15 views

How to avoid violating one definition rule in this case?

We have an existing Mutex C++ class. It have an debug feature to track the owner thread id. So it have an member variable to store this, but because the original developer doesn't want to wast memory, ...
3
votes
2answers
230 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
1answer
32 views

Ask advice on the improvement of my code [on hold]

My original part of the code for a matrix class is like this: Matrix::Matrix(const Matrix& mat) { int i; r = mat.r; c = mat.c; d = new double [r*c]; double* p = d; double* pm = ...
0
votes
2answers
367 views

Is factory pattern a right pattern for the situation described here?

Is factory pattern a right pattern when we want to consolidate the related objects? Problem - In the Set-top box, I have a user-io, basically the interface to control the settop box - The user-io can ...
0
votes
0answers
27 views

Can you write normal Windows applications with C++/CX? [migrated]

Or are you restricted to the "Metro style" applications and Windows Store apps? At first I thought C++/CX would be a good alternative to C++/CLI as it has some nifty C#-esque keywords ('sealed', ...
-1
votes
0answers
13 views

gdb will not run and hit breakpoints [migrated]

I am using unix with a project that deals with C++ source files. In the directoryuser/project/Build, I enter make to compile and link the source files and then go to user/run and enter run.sh ...
2
votes
2answers
68 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" ...
-1
votes
0answers
18 views

Is it possible to pass an exception to a handler and then rethrow the original exception? [migrated]

I am trying to write code which is passed a handler for when errors occur. class Handler { public: virtual void handle(std::exception const& e) = 0; }; class DoIt { Handler* handler; ...
-2
votes
0answers
23 views

How to handle the file more than 2G bytes when convert h264 raw stream to mp4 with MP4V2 lib on android platform? [on hold]

I convert a h.264 raw stream file more than 2G bytes(>0x80000000) to mp4 file, with mp4v2 lib , but it can not be played. But if I read the raw file less than 2G (<0x80000000) then convert to mp4v2 ...
-4
votes
0answers
84 views

Do i have to learn mathematics deeply to be a software enigineer? [on hold]

I do not know nothing about about Software Engineering but I want to be a software Engineer and I am interested in Computer and also I am very bad a Mathematics. Help me out. :)
-3
votes
0answers
96 views

Is there a type safe programming language for compiling kernel code? [on hold]

As per the title, the linux kernel is like 90+% in C/++. The rest is practically all assembler. Is there any language that can be used to make type safe kernel objects? As in not C's level of unsafe. ...
-1
votes
0answers
95 views

Convert an 8 bit data to 3 bit data [migrated]

PROGRAMMING LANGUAGE: C I've a 8 bit data with only 3 bit used, for example: 0110 0001 Where 0 indicate unused bit that are always set to 0 and 1 indicate bits that change. I want to convert this ...
-1
votes
1answer
36 views

migrate a project developed under Borland C ++ Builder 5 to another IDE (Qt or VS) [on hold]

I would like to migrate a project developed under Borland C ++ Builder 5 to another IDE (Qt or VS), also have your opinion on the feasibility and the different phases that you could advise me. I ...
3
votes
1answer
88 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 ...
89
votes
11answers
23k views

What backs up the claim that C++ can be faster than a JVM or CLR with JIT? [closed]

A reoccurring theme on SE I've noticed in many questions is the ongoing argument that C++ is faster and/or more efficient than higher level languages like Java. The counter-argument is that modern JVM ...
-1
votes
0answers
48 views

what is the best book for data structure using c++ language? [on hold]

i am studying data structure with Nell Dale book and i found it hard can you suggest any other book?
0
votes
1answer
309 views

GUI code implementation for specific Window/Form class

Terminology Element/Form Element -> Fields such as text list, combo_boxes, push buttons, etc. Problem I have a program that is basically a fat client that interfaces into a system that keeps track ...
-6
votes
0answers
47 views

If statement for functions in class [closed]

This question is pretty basic. How do you make an if statement for the function Func in the class TheClass? //declare x string x; class TheClass { public: void Func () { if (x == 1) { ...
-3
votes
1answer
54 views

Request for some general advice from someone moving into software development [closed]

I've had a look around the StackExchange sites and this one seemed to be the most appropriate for my question. Apologies if I made the wrong choice, and I'm happy to hear alternative places to post. ...
0
votes
6answers
1k views

Why languages that compile to C/C++ generate unreadable, cryptic code? [closed]

I'm willing to compile certain language to C or C++ for some speedups. My idea was, though, to generate readable code and use structures such std::vector and similar wherever I can, expecting CLANG to ...
11
votes
3answers
1k views

Why can't a compiler avoid importing a header file twice by its own?

New to C++! So I was reading this: http://www.learncpp.com/cpp-tutorial/110-a-first-look-at-the-preprocessor/ Header guards Because header files can include other header files, it is possible ...
24
votes
11answers
7k views

typedefs and #defines

We all have definitely used typedefs and #defines one time or the other. Today while working with them, I started pondering on a thing. Consider the below 2 situations to use int data type with ...
2
votes
2answers
87 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) ...
0
votes
0answers
28 views

C++ metaprogramming - compile time search tree [migrated]

Imagine I have to statically initiailize a search tree each time mine program is executed. Tree t; t.add(1.0, 'Apple'); t.add(2.0, 'Pear'); t.add(5.0, 'Orange'); ... t.add(30.0, 'Cucumber'); .. // ...
3
votes
2answers
126 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, ...
0
votes
5answers
482 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 ...
56
votes
11answers
7k 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 ...
1
vote
2answers
59 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 ...
-2
votes
0answers
30 views

I need a book which explains gui library internals [closed]

I need a book or web contents to explain internal design and implementation of an opensource gui library. C/C++ in linux is prefered. The more detail and code it explains, the better it 's for me to ...
0
votes
0answers
42 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
48 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) ...
7
votes
6answers
13k views

What does it mean to do a “null check” in C or C++?

I have been learning C++ and I am having a hard time understanding null. In particular, the tutorials I have read mention doing a "null check", but I am not sure what that means or why it's necessary. ...
3
votes
2answers
605 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 ...
26
votes
8answers
6k views

Are utility classes with nothing but static members an anti-pattern in C++?

The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as ...
0
votes
1answer
429 views

Interface questions for using Command Pattern and Dependency Injection together

I have many projects that have essentially the same high level requirement: test all hardware on a device. Each device can have a different communication protocol, requires different test equipment to ...
3
votes
1answer
127 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
64 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
101 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
161 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
1k 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
99 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 ...
4
votes
3answers
145 views

Enforcing manual inclusion of a specific header file (banned.h)

Banned.h is a list of ANSI C functions that Microsoft is trying to persuade programmers to deprecate. I already know how to enforce automatic inclusion of banned.h (such as the answer to Ensuring that ...
75
votes
7answers
59k views

When do you use float and when do you use double

Frequently in my programming experience I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
-1
votes
2answers
75 views

What are the benefits of using a unique_ptr when declaring a class? [closed]

I have a class TestABC, I want to declare it using a unique_ptr. But, I am not sure what the benefits of doing that would be. So I want to do something like this: std::unique_ptr<TestABC> ...
1
vote
1answer
49 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
165 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
2answers
113 views

saving connectivity information in a nodes/edges network

I want to implement the A* algorithm. I have a network with Nodes and Edges, both are classes. Now, I am unsure how to approach the connectivity information. Should a node know which edges depart ...
1
vote
1answer
176 views

Where should I place a typedef when used in method signatures in C++?

I'm using an Optional class quite similar to that of boost. For semantic reasons, I switched an attribute of the same (structured) type in some class definitions (and therefore also in method ...
0
votes
0answers
70 views

How to avoid default member construction? [migrated]

I`m implementing move constructor and operator= for my class and I wish to implement moving only once inside operator=(). But member object constructed constructed before constructor body executes and ...