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

learn more… | top users | synonyms

0
votes
2answers
186 views

Difference between Singleton pattern and auto_ptr<> resp. unique_ptr<>

I'm maintaining some legacy code of a physical simulation. The calculation object is build as a singleton, to ensure there is only one instance. A co-worker told me, that singleton are completely ...
2
votes
1answer
264 views

Clearing the lowest set bit of a number

I can see in this tutorial on bit manipulation, under the heading "Extracting every last bit", that - Suppose we wish to find the lowest set bit of x (which is known to be non-zero). If we ...
0
votes
1answer
218 views

High Level Configuration of Constructor Injection in C++

My questions are specifically dealing with dependency injection through the constructor. I understand the pros/cons of service locator pattern, constructor/setter injection, and their flavors, however ...
0
votes
3answers
215 views

Add behavior without changing existing class

I have a class Container, which represents wrapper around std::list. This class contains following public methods: void add(Shape *item) void next() void setBegin() Shape* curr() and protected ...
3
votes
2answers
200 views

Intersection of geometric entities

I was trying to design a small C++ geometric API for learning purposes, but came across a problem when dealing with intersections of geometric entities. For example, the intersection of a line and a ...
1
vote
1answer
417 views

What is the difference between string.c_str() and &string[0]?

What are the differences between string.c_str() and &string[0]? Regarding performance my guess is that &string[0] is a little faster than string.c_str() as it doesn't require a function call. ...
1
vote
1answer
278 views

Language with syntactic sugar that translates to C++ that looks “hand-written”

I'm a college student and I have homework in C++. My professor wants separate hpp and cpp files for each C++ class. And it just didn't feel good how much I had to type, and how much I had to click to ...
4
votes
2answers
790 views

Dota 2 running on Linux, Mac and Windows - How do they do it?

How do Valve create games that run on Linux, Mac and Windows? I imagine they dont really write one version for each platform bec that would just be a nightmare.. or do they? I imagine it is written in ...
3
votes
1answer
261 views

Compiler doesn't inline anything?

I've rolled my own SIMD-accelerated math library. It's gotten pretty complete, so naturally I went to conduct speed tests and optimize it. Btw this isn't premature optimization, the lib is actually ...
1
vote
4answers
489 views

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

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 ...
0
votes
1answer
141 views

Does changing the name of a namespace count as a MAJOR change in semantic versioning?

I'm writing a C++ library, and according to this site here: http://semver.org/, I should increment the MAJOR version when I make incompatible API changes. Is changing the name of a namespace ...
1
vote
3answers
634 views

How to ensure that a member variable is initialized before calling a class method

There's a class with a parametrized constructor that initializes a member variable. All public methods of the class then use this member variable to do something. I want to ensure that the caller ...
0
votes
1answer
188 views

Does C++ support subtyping?

I know it might be a silly question to ask, but I didn't quite get an a absolute clear answer on this matter, so I thought I'd put it here. Does c++ support the subtyping in the sense that it ...
5
votes
4answers
587 views

What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]

AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
48
votes
12answers
3k views

Is it reasonable to null guard every single dereferenced pointer?

At a new job, I've been getting flagged in code reviews for code like this: PowerManager::PowerManager(IMsgSender* msgSender) : msgSender_(msgSender) { } void PowerManager::SignalShutdown() { ...
3
votes
2answers
215 views

Semantic coupling vs. large class

I have hardware I communicate with via TCP. This hardware accepts ~40 different commands/requests with about 20 different responses. I've created a HardwareProxy class which has a TcpClient to send ...
2
votes
1answer
660 views

Is it viable to make a port from a C++ application to Java through LLVM

how viable is it to port a C++ application to Java bytecode using LLVM (I guess LLJVM)? The thing is that we currently have a process written in C++ but a new client has made mandatory to been able ...
15
votes
5answers
770 views

“Whole-team” C++ features?

In C++, features like exceptions impact your whole program: you can either disable them in your whole program, or you need to deal with them throughout your code. As a famous article on C++ Report ...
1
vote
2answers
526 views

Storing a pass-by-reference parameter as a pointer - Bad practice?

I recently came across the following pattern in an API I've been forced to use: class SomeObject { public: // Constructor. SomeObject(bool copy = false); // Set a value. void ...
0
votes
5answers
1k views

Reference vs dereference pointers in arguments C++/C

OK, I'm facing this all the time in many functions I write, which should I use? void sth(int* a) void sth(int& a) Which one is faster, regarding two separate occasions: a is a small variable or ...
1
vote
3answers
336 views

Is it bad practice to check object types with an identifying member variable?

Preamble: I am making a simple board game in C++, in which AI characters move around squares on the board. There are different types of squares, each inherited from an abstract class, each with ...
-2
votes
1answer
162 views

PDF to doxygen - how to do it? [closed]

I have a big pdf with the documentation for a project and I need to render this to doxygen (so take each function from the pdf and write it out into doxygen). Any suggestions on how to do this ...
7
votes
1answer
309 views

Creating an effective C++ library website and documentation

Creating a C++ library also means documenting it so that others can use it, and that documentation can vary dramatically in quality. How should a website for a C++ library be structured so that it ...
-1
votes
2answers
2k views

Want to create a simple gui app using C++ but dont know what to use [closed]

I have learned C++ to an intermediate point and now I'd like to create something beyond a console program. I would like to create a simple program that grabs info from specific text files and displays ...
0
votes
2answers
508 views

C++ control reaches end of non-void function

I have a function, which looks something like this: ClassA& ClassB::Check(int x){ //some calculations in a loop, if a condition is met, a reference to a ClassA object is given } I'm getting ...
5
votes
1answer
259 views

Deploying Qt-based app on Mac OS X

I wrote a cross platform application and I distributed it successfully for Windows and Linux (and tested them on "clean" virtual systems, with no other additional software and/or libraries installed). ...
2
votes
3answers
1k views

Is there any alternative to function pointers in c++?

I am a novice c++ programmer who kept an idea that function pointers are a thing of C and OOP in C++ does not recommend its usage. I know what I write here is vague/broad. But it will be great if ...
1
vote
1answer
501 views

c++ web with nginx - Do I have to worry about thread safety?

I am currently developing my website with c++. I know that nginx handles connections with multiple threads to provide high performance. And not all c++ code is thread safe. What's the relationship ...
2
votes
3answers
343 views

What code lays behind C++ exception?

In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data ...
4
votes
3answers
1k views

Is it possible to combine C/C++ with web languages? [duplicate]

I would like to create a web application (meaning that will run from browser). The point is that I want to write just the UI in HTML5 + CSS + JS (or maybe even some PHP). On the other hand, I want to ...
4
votes
3answers
274 views

Is it OK to use same variable to store similar stuff sequentially? [duplicate]

Say I have a variable name len in a function and several strings. Can I use this to store length of those strings one after the other or should I create separate variables? Basically this: size_t ...
-1
votes
1answer
136 views

Integrate a Python Project with a Visual Studio C++ Console Application?

I now have a Python project that is in charge of generating the simulation data and visualizing the simulation and processed data. A C++ console application is already available in my Visual Studio. ...
0
votes
1answer
546 views

efficient way to count number of swaps in insertion sort

I am browsing some online coding challenge online and got struck somewhere . Objective of program is to find maximum number of swaps required in sorting an array via insertion sort in efficient time ...
1
vote
2answers
311 views

developing an android app that include a C++ toolkit [closed]

I'm a java developer and I want to develop an android app that capture a photo and extract its bags of visual words. To extract those bags of words I use the TOP-SURF toolkit which is written in C++ ...
1
vote
2answers
285 views

Client-server application design issue

I have a collection of clients on server's side. And there are some objects that need to work with that collection - adding and removing clients, sending message to them, updating connection settings ...
2
votes
3answers
284 views

Can compilers check whether certain axioms hold for a user defined type?

Suppose the following type is defined (C++ syntax, can be conceptually applied to any statically typed language.) class T { int val; friend bool operator<(const T& lhs, const T& rhs) ...
3
votes
3answers
915 views

Is it bad practice to make an iterator that is aware of its own end

For some background of why I am asking this question here is an example. In python the method chain chains an arbitrary number of ranges together and makes them into one without making copies. Here is ...
1
vote
2answers
979 views

Are Nested Static Library dependencies possible?

I am working in QT . Can a static library depend on another static library?(Static Lib is made by linking another static lib) If yes, is it possible that after linking to lib2, the generated ...
1
vote
1answer
373 views

Why using FMOD?

I'm creating a music player using C++ and QT, everyone says use FMOD. But QT has all the components, I can play audio, create playlist, and everything i need, so what does FMOD offer me, that can't be ...
16
votes
7answers
1k views

To rewrite or slowly refactor old C++ project [duplicate]

Our team has recently inherited a relatively large project from another company (~250k lines). It was developed using C++Builder and we intend to port the Ui side to Qt. Most of the Ui code is ...
1
vote
1answer
404 views

Why isn't iostream included as a header file anymore?

First of all I have gone through this question Why is #include <iostream.h> bad? and there the reason was simply that it is outdated but I personally think that as a header iostream was better ...
3
votes
3answers
786 views

A question about storing passwords

I'm creating a program (in C++) that will password protects its user's database (.dat) file. I'm confused on where to store the password? In the user's database file or somewhere else. I'm new to ...
1
vote
1answer
402 views

How to design a log() method that can easily be accessed from the outside of the Console class?

Recently my team has programmed a custom developer console in a video game which can easily be hidden or displayed, because it's more comfortable and less of a hassle. The Console class contains a ...
3
votes
2answers
558 views

How to deal with pointers from child to parent?

I have a class that represents a file in specific binary format on disk (the parent in the title) and another class that represents an object inside that file (child). When the object changes, it ...
-5
votes
2answers
7k views

How do I easily print number triangles? Using for loops [closed]

I know how for loops work and what a nested loop is but I get very frustrated while printing those number or asterisk triangles in java. It makes me wanna quit learning programming :( Please someone ...
2
votes
1answer
259 views

Is nesting typedefs a good style?

Let's say I have a namespace my and this namespace contains a class foo. What should I prefer nesting typedefs into my class or hold it in my namespace? namespace my { class foo { // some stuff ...
6
votes
6answers
620 views

Should my team use some common well-regarded coding standard as a basis for own own?

The R&D team I'm in has decided to adopt a coding standard. We have only recently formed, and have too little code and common coding time of our own to base our standards/conventions document on ...
2
votes
2answers
222 views

When is it okay to log filename/line information for errors?

We have a closed-source commercial C++ application. Some of our logged error messages are in plain English like "ERROR: could not read file 'foo'". While others use a macro to print filename/line ...
17
votes
2answers
675 views

Why does Java not put the filename in args?

In C and C++, the main method holds the filename in the first position of the array at argv[0]. In Java, however, the filename is not included in the args string array. Is there a practical reason ...
1
vote
1answer
290 views

a lot of small objects - OO pasta [closed]

In the code I am working on, there are a lot of really small objects like: class HasFieldLameSetter { public: HasFieldLameSetter(field& p_):m(_p){} void set(bool p2) ...