Tagged Questions

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

learn more… | top users | synonyms

-2
votes
0answers
19 views

How to compare two chars in C++? [on hold]

I have to extract 2 chars from a string and test them on being equal. How do I do this? My approach if (s[1] == s[2]) ... doesn't work.
4
votes
0answers
50 views

How to prevent others from using non-thread safe variables in a multithreading environment?

I have an application written in C++ that was originally single threaded, but, due to the increasing complexity of this project, I'll need to expand it to at least two or three threads. There are ...
-6
votes
0answers
30 views

Can Some One look at this [on hold]

Im making a command line version of Tick tack Toe for my class yet I keep running into the same problem it keeps stoping after player one take his first turn no player 2 no call back to player one ...
-3
votes
1answer
79 views

What do you think about GUI-programming in Qt and all other frameworks usefullnesses [on hold]

What do you think about coding and desining? I mean, should we use code rather then designing all in forms. I think, it's kinda lazy to click in forms some buttons. Programmer should code, BUT i'm a ...
-1
votes
5answers
504 views

Determining the winning condition for Tic-Tac-Toe [on hold]

I'm writing a tic-tac-toe game in C++ and now I found a function to check if a player has a winning board for a connect four game. The function looks like this: bool haswon(int64_t board) { ...
-1
votes
0answers
38 views

SCJP like book for C++ [on hold]

I read SCJP study guide two years ago and it helped me become a better Java programmer. I would like to use the same success recipe, so I'm asking : Do you know any C++ book that is structured like ...
0
votes
2answers
97 views

Why are the raw pointer values being overwritten/falling out of scope

I have a C++11 function making calls against a legacy C function. I thought it would be good to create worker threads(using std::thread that will then pass variables to the C function. However, it ...
-2
votes
1answer
90 views

How would I go about editing memory in a Process via C++ DLL Injection? [on hold]

How would I go about editing memory in a Process via C++ DLL Injection? More specifically, how could one find the target location of the stored memory, and edit it using a C++ DLL that gets injected ...
-2
votes
0answers
60 views

Developing a Phone OS [on hold]

I have created a project for myself: Develop my Own Operating System.. for a Mobile Phone (touch screen). I am new to this whole thing, I've started learning C and C++ but only in theory as of yet. ...
0
votes
0answers
78 views

What means that a paper has been adopted for pending C++ standard? [on hold]

For example: "New core language papers adopted for C++17" http://isocpp.org/blog/2014/11/new-papers-adopted-for-cpp17 "New standard library papers adopted for C++17" ...
3
votes
2answers
1k views

Every function is a closure?

Wikipedia says, that closure - is a function, which has an access to variables, declared outside of the function. There is even an example: function startAt(x) function incrementBy(y) ...
1
vote
4answers
682 views

try/catch open/closed principle violation

I have three or more different custom exceptions that a class can throw and I need to use try/catch in order to discover which exception was thrown. In my point of view this piece of code violates ...
-1
votes
0answers
13 views

How to stop copying into array using fscanf when its the end of the line? [migrated]

I have a file that has lines like Bob, 2,3,13,4 Jim 3,4,15,3 ... and I'm trying to copy into my numbers array only the integers in each line, so that I could do some math with them. Problem is, I ...
0
votes
0answers
44 views

Accessing a stateful managed object from native code via a static variable [migrated]

I need to create a native C++ DLL that will be an interface/wrapper over a C# class. I've never done anything like this before, but my design is basically the same as this. In other words: I have a ...
-4
votes
0answers
56 views

Internationalization of C++ application with minimal effort [closed]

I have ready and working C++ application. It uses Win32 API. This application is built by Visual Studio. The application contains about 100 strings hardcoded in a source code. I need to translate the ...
38
votes
9answers
7k views

What did people do before templates in C++? [duplicate]

I am not new to programming, but I am one that started a few years ago, and I do love templates. But in the before times, how did people deal with situations where they needed compile-time code ...
0
votes
3answers
231 views

Using PHP or C++ for in real world electronic devices

I want to use my programing skills to make my day-to-day life easier, to do this I want to be able to program in my appliances like alarm clock or microwave or refrigerator, air conditioner etc, wish ...
3
votes
3answers
300 views

Should we add constructors to structs

We often use c++ structs to define data structure as opposed to class which can be a complete module with member methods. Now deep down, we know they both are the same (loosely speaking). The fact ...
-1
votes
1answer
171 views

Writing an Operating System in C [closed]

I've done some research in building an OS and I know that it has to be made using the assembly language. I've also seen that it can be built using the assembly language with C/C++. I was wondering ...
0
votes
1answer
164 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
5answers
186 views

Race conditions in JVM languages versus C/C++

I was thinking about thread synchronization issues in compiled languages like C++, versus synchronization issues in languages like Java. I'm wondering how a JVM language like Java doesn't (at least ...
-2
votes
0answers
33 views

Help me fix my update function for projectiles. The bullet moves faster the closer xTarget - xPos is to 0 [migrated]

Here is all the relevant code. This gets run when the projectile is initialized: slope = (yTarget - yPos) / (xTarget - xPos); if (xTarget >= xPos) xDir = 1; else xDir = -1; if (yTarget ...
7
votes
5answers
706 views

Coding style issue: Should we have functions which take a parameter, modify it, and then RETURN that parameter?

I'm having a bit of a debate with my friend over whether these two practices are merely two sides of the same coin, or whether one is genuinely better. We have a function which takes a parameter, ...
3
votes
2answers
210 views

What's wrong with statically linking the STL into multiple shared libraries?

Here is the scenario: libA.so and libB.so both statically link to the same STL. libA.so has a public API that returns a std::string. libB.so calls this function and receives a copy of the string. ...
1
vote
3answers
219 views

Including extra headers that I do not really need

I always wondered what are the effects of including not needed headers to the final executable once compiled. In my code some times I may included many different headers that I do not need (or I used ...
3
votes
2answers
105 views

OOP CLI menu structure organization?

This problem has kept me from pursuing a project I'm working on because it influences the entire structure of the application. This question has been briefly touched on here, but I feel that it wasn't ...
-1
votes
1answer
64 views

Creating a new type of project file [closed]

I'm starting to work on a project where it would be quite useful to have something like a project file that holds all the data being used in a form that can't be opened/modified/used in anything but ...
23
votes
7answers
2k views

Is it good practice to rely on headers being included transitively?

I'm cleaning up the includes in a C++ project I'm working on, and I keep wondering whether or not I should explicitly include all headers used directly in a particular file, or whether I should only ...
0
votes
3answers
151 views

Store an object's name in the object or externally?

I'm in the process of building an application which needs extensive logging of points in time at which certain events happen. For example when it renders a sequence of different shapes to the screen ...
0
votes
1answer
111 views

Should I throw std::bad_alloc?

I am allocating memory on the stack, and distributing it manually to shared pointers. I end up doing something like this at startup (I've simplified it by ignoring alignment issues): char pool[100]; ...
0
votes
2answers
121 views

how to carry a specific number of significant figures while computing? [closed]

How to carry more or less than six significant figures (4 , 5 , 7.. ) in the computation while running a program ? i'm writing a program to solve a system of linear equations /using Gauss elimination ...
2
votes
2answers
164 views

How can I get better than O(N^2) space complexity for a type sequence search?

Suppose I have a type sequence through which I want to search: template <typename...> struct TypeSequence { using type = TypeSequence; }; I want to create a metafunction Search that returns ...
0
votes
2answers
417 views

Does any other language use the uniform initialization syntax found in c++? [closed]

Are there any other languages that use the new C++11 uniform initialization syntax thoroughly throughout the entire language, or is this entirely a C++ idiom at this point? I tried googling and ...
0
votes
0answers
66 views

In-place merging of sorted intervals in an array?

So I have code producing k sorted intervals in an n-sized array. What I'm brainstorming is the possibility of in-place merge of these intervals into a single sorted interval/array. The problem is ...
0
votes
3answers
110 views

Alternative to printing debug information to stdout\stderr [duplicate]

I currently have a long running application on an embedded Linux environment and all debug messages are currently being outputted to stdout using printf. This isn't ideal for special users who ...
-1
votes
1answer
73 views

Cross-platform CI builds [closed]

Does any Continuous Integration system out there offer building a project on several operating systems at the same time? Like, building the code on Windows, Linux, *BSD and OSX per commit? I ...
1
vote
0answers
64 views

Is conversion from C/C++ to Verilog/VHDL for FPGA a derivative work? [duplicate]

Say I have a C/C++ software licensed under GPL that gets converted into hardware design. By this conversion I mean that the exact functionality of the original software is being programmed into an ...
3
votes
2answers
318 views

How to avoid long call chains?

I have a hierarchy of objects, mostly connected by composition. I.e. (not showing the class methods for readability): class A {} class B {A a;} class C {B b;} etc... class Z {Y y;} class Z provides ...
1
vote
0answers
37 views

Qt: internationalization of images [migrated]

I am aware of utilities like GNU gettext for making the software multilingual. You give it a string id and it will return the translated string. But I also need this for images in Qt. For example, if ...
1
vote
2answers
135 views

Will there be a memory or processing time difference between a class member function and a global function

I'm writing a neuron network simulation program and every operation or additional byte per neuron scales insanely. I prefer C++ as a language over the others, but now I'm wondering if the class ...
0
votes
1answer
70 views

Extending a class for debugging: public API, hidden implementation or something else?

I'm working on a fairly large project that involves 3D drawing, and I want to add some visualizers (for example, to see the bounding boxes of the objects) to make debugging easier. However, I'm having ...
-2
votes
2answers
154 views

Why doesn't array declaration guarantee proper memory allocation whereas malloc does? [closed]

In C++, when I declare an array like int array[10];, it sometimes uses memory assigned to other variable where as this problem is non-existent when I use an integer pointer and malloc to allocate ...
3
votes
6answers
229 views

Explicitly define enum values, even if the default value is the same?

There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if ...
5
votes
2answers
505 views

Robustness and pointer safety in C++

I'm currently building a server responsible of storing and managing few million records of fairly complex and interconnected data. For reasons beyond my control the work has to be done with C++. I ...
1
vote
2answers
272 views

What is the purpose of creating a member function with the same type as its class?

I'm sure I'll botch some of the specific terminology, but what is the difference between object and object2 in this implementation? Is the only purpose of the first method (prototyping the class's ...
1
vote
2answers
90 views

What is the name of a type that is defined from a template?

To give a complete example, let's say I have a template class that I now use to generate a type definition: template <typename T> struct A {}; using X = // I'm not asking about this ...
0
votes
1answer
99 views

Is there a good name for this pointer template? [closed]

I'm looking for a proper name of a class template with the following features: It's interface would look something like this, where Foo is a placeholder for the name I'm looking for. ...
-1
votes
2answers
124 views

Does GCC optimize code to remove useless variable read operations? [closed]

I'm using GCC on ununtu 14.04. My program is written in c++ and in a case i need to check the amount of time the program needs to read a large integer array. what is the best way to do this without ...
3
votes
1answer
242 views

Is checking for cin.eof() really necessary?

I have written a simple program that reads character input from the keyboard within a For loop. My professor has taken away 10 points for not checking the input using cin.eof. I don't understand why ...
2
votes
3answers
164 views

Disallow non-local storage of an object

I need to write a class in C++ that acquires a hardware resource and releases it again when it is destroyed. Basically that can be done in the constructor and destructor of the class. The difficulty ...