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

learn more… | top users | synonyms

-5
votes
0answers
22 views

How to play sound in C++ using android C++ compiler? [on hold]

I want to play sound (mp3) in C++ using C4droid. I searched on web, but I can't use "Window.h" library. Is there any way to play sound in C++ using a Android C++ compiler?
-6
votes
0answers
12 views

CPP | std stream printing error [migrated]

I am currently programming an int matrix in cpp. I wanted to add a printing function that prints the numbers in the following way: 1 2 3 7 6 9 19 23 9 (every 2 intergers are seperated with a ...
-2
votes
0answers
36 views

Free all surfaces in SDL?

So I have a bunch of SDL_Surface*'s in a C++ program. I want the program to free all SDL_Surface*'s when the program closes by default but I can't find a function to do it. I'm currently using an ...
-5
votes
0answers
29 views

Meaning of Abc##Def in C++? [on hold]

I saw this statement in a C++ program: extern "C" void * Class##Factory(arg_list); What does the "##" mean here?
-2
votes
0answers
49 views

What's the lhs/rhs equivlent of a single parameter? [on hold]

Typical operator overloading conventions go like this: MyObject operator+(const MyObject& lhs, const MyObject& rhs) { return MyObject(lhs.my_value + rhs.my_value); } What would be the ...
0
votes
0answers
86 views

Integrate C++ DLL with C# GUI asynchronously (design issue)

This is more a design than an implementation question. I am aware of how to integrate a C++ DLL within a C# main app that acts as GUI. Believe me that I've read all other questions on similar topics, ...
0
votes
1answer
131 views

What is the difference between “Wide character” set and “Unicode character set”? [on hold]

Today I was reading my favourite C++ Programming book (C++ Primer Plus) and the section which was about variables and character sets in C++, however I got really confused about Unicode and Wide ...
1
vote
1answer
80 views

C++ Runtime and runtime-linking

I was installing boost and I came across an option named "runtime-link". After searching a bit, I came across yet another complex topic: "runtime system" that according to Wikipedia: The runtime ...
0
votes
0answers
66 views

How to achieve time localization in c++? [migrated]

I'm using the time_t and ctime header to get the time in my app, and it's all OK. The problem is that, the week days and months are displayed in English and i want them to be displayed in my language ...
8
votes
1answer
163 views

C++ serialization design review

I am writing a C++ application. Most applications read and write data citation needed and this one is no exception. I created a high level design for the data model and serialization logic. This ...
1
vote
1answer
79 views

When's a resource a resource?

So I have a rendering engine, and I have a resource manager that adds classes that derive from type 'Resource'. It's a very flexible and generic resource manager, of which only one can exist (it is a ...
0
votes
1answer
69 views

Deciding on a software license for a C++ API [closed]

I have designed and developed a C++ API. Its dependencies are: BLAS - custom license - http://www.netlib.org/blas/#_licensing LAPACK - modified BSD - http://www.netlib.org/lapack/LICENSE.txt GLPK - ...
2
votes
1answer
174 views

Refactoring a god Manager class

I am running in the exact problem Robert Martin mentioned when having a class named Manager, mine has too much (redudant) code. I am writing a system doing computations on many buffers containing ...
4
votes
5answers
667 views

Checking array size in C/C++ to avoid segmentation faults

So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault ...
0
votes
0answers
48 views

Dll that uses services from its caller [closed]

I am making simulators with graphic engine based on c++. I decided to make a dll for shells/bullet shooting for the use of the simulators. The thing is that the dll need information of the terrain ...
0
votes
1answer
149 views

What is an efficient data structure for syntax highlighting in text editors?

I'm creating a very small text editor in C++ with the ncurses library. So far, it works great. I have implemented the Gap Buffer data structure to make the editing more efficient than a line-based ...
0
votes
0answers
81 views

Running a C++ code written for Windows on Amazon Web Service [closed]

I am new to this website and this is a general question that I know many similar people want to know: I am a C++ Windows software developer, my customers are supposed to buy my software and install ...
4
votes
1answer
115 views

Genesis of C++ temporary object lifetime extension

I'm revising a proposal to expand the C++ feature where "temporary" objects cease to be temporary when attached to a name by binding a reference. Here's a sample of the classic behavior (not the ...
0
votes
2answers
90 views

How to initialize an array of const char * strings and initialize each one of the strings contained within? [closed]

I'm trying to initialize an array of 50 strings, each one containing just a period. Here is what I am using: const char ** dotboard = new const char * [50]; That allocates memory for the string ...
4
votes
2answers
285 views

Can higher order functions ever be pure?

I was thinking about pure functions especially in the context of C++, which of course is not a purely functional language, and was wondering if higher order functions in C++ can ever be considered ...
-1
votes
0answers
9 views

send data socket TCP,ERRoR sendig: Bad file descriptor [migrated]

I want to create data and then send to server . data(information on each sensor) should create in Network.cppafter new sensor added( each sensor is an new network) and send with client.cpp ,I use ...
4
votes
1answer
58 views

Makefile for library project to be able to compile the unit tests and the demo program using make

I am new to makefiles and I am developing a (non-executable) library in C++. Additionally to the library I have (executable) unit tests and an (executable) demo program. I would now like to be able ...
2
votes
1answer
84 views

Multithreading with triple buffer, do I have to do the waiting for the condition variable?

I have a triple buffer implementation that is often used in threads in such a way that when new data is expected, there's always a WaitData(n) function called on the buffer (A condition variable's ...
3
votes
3answers
294 views

Possible alternatives to copy constructors

In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much ...
5
votes
0answers
100 views

Key / Value store development porting to modern C++

I am developing a database server similar to Cassandra. Development were started in C, but things became very complicated without classes. Currently I ported everything in C++11, but I am still ...
0
votes
0answers
33 views

Qt / C++ internal API design for slightly similar web services

in my application I provide a Qt/C++ wrapper to certain web services based on the Danbooru software. Basically the API wraps a series of REST calls and produces / parses the JSON responses to display ...
0
votes
0answers
61 views

What does the const keyword do in an operator definition? [migrated]

I don't understand what the const keyword is used for in front of the return type and after the parameter list of this operator definition. This is taken from an example from a book. const char& ...
5
votes
3answers
1k views

Is it a common practice among professional programmers to avoid the use of raw pointers? [duplicate]

C++ tools and libraries have become more powerful than ever. For instance, we can replace arrays by vectors. We can replace pointers by references. We can use smart-pointers. Is it a common practice ...
0
votes
0answers
22 views

How can I automate updating code on an integrated device with files and a MySQL database?

I have an integrated device that has a program in it currently written in Node.js. So, naturally, there are a whole bunch of files that it needs to run. Also, there is a MySQL database that it uses ...
-2
votes
1answer
60 views

What's an effective threading structure for NIO and server performance in C/C++? [closed]

I run into this issue where if I do a read to check for data too often, my CPU skyrockets, and if I don't check often enough, it's slow for client performance. What's an effective way to deal with ...
-5
votes
0answers
40 views

C++ - how is it with real numbers? [migrated]

int main() { float fNumber = 1234567.89; cout << (fNumber + 1) - fNumber << endl; cout << (fNumber - fNumber) + 1 << endl; } results: 0 1 Can anyone explain ...
-3
votes
0answers
35 views

How to define member function in separate source file? [migrated]

Consider following two programs. p1.cpp #include <iostream> struct test { void fun(); }; int main() { test t; t.fun(); } p2.cpp #include <iostream> void test::fun() { ...
2
votes
3answers
233 views

How to share data members between classes in C++ without violating encapsulation too much

In C++ let's say I have some class A: Class A { int a1, a2, a3; void foo(); } and I need to use a subset of members (a1, a2) in a member function for a second class B. ...
2
votes
1answer
97 views

Template Function: Passing Iterators

I am struggling with making a design choice in the following setup: I am writing (C++) functions which take a pair of iterators (to template containers) and compute a return value of the same type ...
1
vote
4answers
122 views

Better way of handling pre conditions and logging

1. Imagine you have the following: void Foo::doFoo() { if (!isConditionValid()) { log("doFoo not possible because condition is not valid"); return; } if ...
-2
votes
2answers
141 views

Is it ever overkill creating classes/objects? [duplicate]

I just learned how to create a class or object in C++ and I'm practicing and learning. I'm writing a text based version of a popular board game and I was wondering if it's overkill creating a class ...
1
vote
1answer
45 views

Qt/QML/C++ Application database connection object visibility

I am working on some Qt/QML/C++ app and I've got myself into some kind of dead end. Namely, this app uses mysql database and here is my questions: Is performance hurt if I instantate new database ...
4
votes
0answers
61 views

Strategy for OS X and downlevel version of C++11 library?

I think I've found myself in a situation where things are quickly spiraling out of control, and I'd like to get some feedback to select a way to proceed. BACKGROUND I'm working with a library based ...
4
votes
0answers
83 views

What is the correct place to put checking of conditions in this use case?

Here is the situation: I have a database and a class that is basically a representation of a set of fields of different tables in it. Let's call it Message. "Message" does not know of the database ...
3
votes
2answers
132 views

Are string characters assigned a numerical value in context of how they are assigned in a programming language?

For context I am fairly new to programming after returning back to it after programming a number of years ago... I was reading Bjarne's intro programming with C++ and was wondering if alphabetical ...
0
votes
3answers
118 views

A secondary “type system” for references?

I'm designing a language and was wondering how to incorporate C++-like references with regards to their place in the type system. I think they're useful for operations like indexing and dereferencing ...
3
votes
4answers
193 views

Design: Lisp (or other scripting language) as an interactive interface for C++?

I'm working on a medium size C++ project (will probably end up around 50k lines) and I have to provide an interactive terminal interface. The program produces scientific data as an output and the ...
0
votes
0answers
41 views

Only one case of base class function member executing on derived class object [migrated]

I have a derived class Circle of base class Shape, where each class has its own print, collide, merge, type, etc functions. I instantiate a bunch of Circle objects and put them into a container (its a ...
1
vote
1answer
82 views

How to handle design changes for auto_ptr deprecation in C++11?

We are testing a library under C++11 (i.e., -std=c++11). The library uses auto_ptr and this pattern: Foo* GetFoo() { autoptr<Foo> ptr(new Foo); // Initialize Foo ...
1
vote
1answer
154 views

What would be a reason not to embed JS in C? [closed]

I'm working on an opensource application that processes JSON in C, because I would like to make it easier for people to help me in the project and because JSON is so close to JS. I want to embed a JS ...
1
vote
0answers
62 views

Pointers vs IDs for “context-specific” functions

I need to be able to load, use, and free resources from a single monolithic object. I have two requirements: 1. That the resource loaded is owned by the object that created it and 2. All objects in a ...
2
votes
2answers
175 views

Is it bad practice to use constant variables with global scope in C++?

So I was reading section 3.2 (One definition rule section) in the latest working draft of the C++ standard and came across this: Every program shall contain exactly one definition of every ...
2
votes
1answer
213 views

How often should RAII be used? [closed]

I've been attempting to learn C++, but it is famously plagued by bad tutorials. I learned about a clever little trick called RAII (Resource Acquisition is Initialization), where one wraps a heap ...
6
votes
5answers
1k views

C++ Iterators: Best practice to represent end of range - Last or Beyond-last?

I am writing a library which deals a lot with sub-sequences of ordered containers. So for example I have a container (1,2,3,4,5,6) and a user wants to access (3,4,5). I am providing the subsequence ...
4
votes
2answers
114 views

C++ design for encoder/decoder classes with different stored types

I need to handle different elements in a vector, each element owning a specific parameter (integer or string), so that I can easily handle encoding/decoding of a series of elements. Encoding a list ...