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

learn more… | top users | synonyms

0
votes
0answers
8 views

Project Organization in C++

Even though I have a decent bit of professional experience with object oriented programming in Java and a basic familiarity with C, I've run into a bit of a mental block with C++ that I was hoping ...
0
votes
0answers
8 views

C++ Snake Game Fruit: Change Coordinates or Spawn New Object?

I've decided to lean SDL and make a Snake game. I have gotten to coding the spawning of a fruit, which the snake eats to get longer. Every time the snake eats the fruit, the fruit needs to change to a ...
-1
votes
0answers
18 views

Implementation of qsort

I have been looking for implementation for qsort but using google I find implementation for something like this void qsort(int[] arr, int left, int right); What I want is implementation for ...
-1
votes
2answers
115 views

Is main() function better on top of all other functions? [on hold]

My college professor told me that main functions should be defined on top of other function definitions. We should use a forward declaration in order to accomplish this (we use C at that time). So yes,...
-3
votes
0answers
39 views

Help with SIMD algorithm implementation [on hold]

Hello guys i am really stack i need to implement matrix multiplication algorithm using SIMD but I don't know too much of c or c++ and i am having a bad time looking for a library with good ...
0
votes
0answers
48 views

Linked list pop_back implementation ignores pointer-to-nullptr [migrated]

Let's assume I'm only allowed to use new and delete and no smart pointers in my implementation. I am not using sentinel nodes. Below is my implementation for pop_back: void sLinkedList::pop_back() { ...
-5
votes
1answer
64 views

what to ask for from developer while delevering ios and android app? [on hold]

I am outsourcing a productivity app on android and IOS. however, I want to be able to maintain and update the app with an in house team after I receive the final version. what shall I ask from the ...
0
votes
1answer
87 views

Syncing data from memory process (C++) to database

I have a C++ program that read game data from memory process. For example, int points = 0; while (1) { points = ReadProcessMemory(..) // points will be read from game's memory Sleep(100) // Don't ...
7
votes
1answer
189 views

Can the C++ template system be used to perform type safe operations of the relational algebra

Assume that the parameters of functions representing operations of the relational algebra are represented by individual types: structs or classes. An operation such as (natural) join will have ...
1
vote
1answer
76 views

Inner and outer class relationship: should outer class be friend of inner's?

Is this design bad? Does it break encapsulation? The structure class B is a component of class A. Therefore, class A needs access to class B's members. Let a house be class A. Let a housekeeper be a ...
0
votes
0answers
40 views

What's an optimal procedure to create a connected cyclic grid of nodes and edges for A* pathfinding

like the title says, I'm trying to create a grid of nodes that hold edges or connections to each other so I can perform A* algorithm to have objects traverse across them as seen in your standard RTS. ...
0
votes
2answers
157 views

IF statement with OR logical operator

Just a basic question on IF statements in programming languages, specifically C++. Consider the following basic code example: int i = 2; if(i == 2 || i == 4) { //do something } Because the ...
6
votes
5answers
378 views

If A has B and B holds reference of A, is it a flawed design need to be fixed? [duplicate]

Suppose, I have class Boss and Worker; Boss has a Worker and Worker holds a reference of Boss: Boss.h #include "Worker.h" class Boss{ public: Worker worker; }; Worker.h class Boss; class ...
1
vote
1answer
127 views

What are the significant memory management models aside from Java (GC) and C++ (manual approach)? [closed]

There are at least two distinct memory management models: Java (we do it for you) C++ (it is your responsibility) I have two questions: (1) Is GC language specific or compiler specific? (2) Do ...
4
votes
1answer
88 views

Do I need to declare a delay timer variable as volatile even if I access it from another module

This is a question more about using volatile to prevent optimization than about caching write/read of a variable. Particularly timer delay variables since I don't want to declare everything volatile ...
1
vote
0answers
21 views

Zeromq bidirectional asynchronous transmission?

I have a system which consists of two applications. Currently, two applications communicate using multiple zeromq publish/subscribe sockets generated for each specific type of transmission. Sockets ...
9
votes
5answers
879 views

Techniques for ensuring cross-platform compatibility (C++)?

I was finishing one of my earliest C++ projects which is (according to the framework) supposed to be cross-platform. I developed the project fully in Windows and Visual Studio, thinking that since the ...
1
vote
1answer
61 views

Strategy for Binary File Format Description to C++ Implementation

I am dealing with a lot of legacy, reverse engineered binary file formats, often with lost source code and reading/writing these files needs to be recoded in C++. I am wondering if there are good ...
0
votes
3answers
282 views

If of loops or loop with if

Assuming the compiler is smart enough to only evaluate the if in the second example once, which version should one (semantically) use and why? if (b) { for (auto a : as) { foo(a); } } else { ...
0
votes
0answers
55 views

Pointers on porting a c++ workflow domain specific language to javascript

I am writing a game in c++ with the v8 javascript engine embedded in it. I have a c++ workflow system I use to tell things how to do specific things. It's nice and I like it, but I need it to work ...
2
votes
1answer
97 views

Writing a non-monolithic database wrapper

I have a SQL database to which I store and from which I read several objects into my C++ code. I wrote a single database wrapper which handles all the reads and writes to the DB. Of course this ...
-1
votes
1answer
142 views

How to signal a loop to continue the execution instead of using sleep

I am trying to create a thread that will sit and wait to detect new objects in a vector (the queue). Using a loop will crush the resources on the given machine, so I am trying to figure out how I can ...
-5
votes
1answer
221 views

Why code in C instead of C++ [closed]

Why code in C? Isn't C++ basically C but with better features? Why do people still use C? Would it be easier to make a game with C or C++?
-4
votes
0answers
53 views

how to create a pipeline code which interfaces between Borland and visual studio platforms?

what pipeline program will act as a interface between visual basic C++ builder and Borland 5.0 they must fulfill these- a C/C++ code which will be a pipeline method interfacing between C and C++ ...
3
votes
7answers
563 views

C++ delete vs Java GC

Java garbage collection takes care of dead objects on the heap, but freezes the world sometimes. In C++ I have to call delete to dispose a created object at the end of it's life cycle. This delete ...
48
votes
8answers
13k views

What happens to garbage in C++?

Java has an automatic GC that once in a while Stops The World, but takes care of garbage on a heap. Now C/C++ applications don't have these STW freezes, their memory usage doesn't grow infinitely ...
1
vote
1answer
55 views

Chain accessors or return the value of private pointer

hopefully the title isnt too confusing, I am having trouble thinking through what best-practice dictate I do in this situation. Say I have the following class structure Class A { public: bool ...
1
vote
1answer
159 views

is this a good design

For example, I have a clan and a character. There's a character that is the leader. To give the clan a specific feature, some money from the character is required. I don't want to have too much tight ...
1
vote
1answer
105 views

Using asynchronous calls for heavy IO operation: How to prevent crushing the CPU?

I have an application that reads a large binary file (1GB on average) and compresses into a bzip2 archive. I started out at first compressing these files synchronously, as I didn't want to impede ...
3
votes
1answer
168 views

Potential legal issues with lock-free / wait-free structures / algorithms

While researching the subject matter - lock-free and wait-free data structures - I'm seeing a worrying amount of mention of patents with this area. I've hobby-researched compression algorithms years ...
-2
votes
0answers
30 views

Unable to install opencv 3.1 with visual studio 2013 [migrated]

I downloaded opencv 3.1 (110MB) from the official site and I followed this tutorial and after setting the environment variables and project settings, I always get an error : Link error : Can not ...
1
vote
3answers
157 views

How do you quickly test C++ code?

I'm working on a series of small projects (~1000 LoC each) on my own in C++. My background is in Python, where I'm used to being able to test out small changes in my code in by loading it into a ...
0
votes
2answers
86 views

What are the prerequisites to start with OpenCV in C++?

I'm an intermediate C++ programmer. Do I need any math knowledge in order to build computer applications using openCV?
0
votes
0answers
50 views

Should frequent Fonts, Colors, Pens etc be “Cached”

I am creating a game, currently everything redraws every 50ms, and that involves quite a few Gdi Objects. Here: Gdiplus::Pen outlineScrollPen ( Color (200, 0, 0, 0), 4 ); ...
1
vote
2answers
110 views

Ideal OOP Design

After learning OOP design then I got to know my programming way was not correct. One should convert physical entities or logically separable components into classes which are reusable and have their ...
4
votes
5answers
199 views

How to store math expression in c++ list

I am parsing a infix math expression to a postfix form. I want to store it in a list like [4.5, 3, 0.25, +, -] so that I can process it once it's parsed. I could store it in a string again, but I ...
0
votes
3answers
131 views

A few questions about initializing variables

I'm in an introductory programming class and we're only in lesson two, so try to keep terminology simple, ha. I'm a bit confused about when you need to and when you don't need to initialize a ...
31
votes
12answers
4k views

Is it a code smell to store generic objects in a container and then get object and downcast the objects from container?

For example, I have a game, which has some tools to increase the ability of the Player: Tool.h class Tool{ public: std::string name; }; And some tools: Sword.h class Sword : public Tool{ ...
0
votes
2answers
147 views

Compiling source code using c++

Last year, in university we used the library SDL to create a game from scratch. So I though of developping a game engine based on SDL. I will be using Qt to do the UI and SDL to implement the core of ...
4
votes
0answers
97 views

Does it make sense to apply the principles in Redux to OO languages?

Redux is essentially functional programming, and it makes a lot of sense. As I move back to a non-javascript OOP language in a different project I would like to apply the same principles such as ...
120
votes
15answers
29k views

Why do people use C if it is so dangerous?

I am considering learning C. But why do people use C (or C++) if it can be used 'dangerously'? By dangerous, I mean with pointers and other similar stuff. Like the Stack Overflow question Why is ...
1
vote
2answers
63 views

Installing multiple versions of software with git

I'm really struggling to understand git, so here's a tighter rephrasing of a previous question I had asked. I'm going to explain a hypothetical scenario, detailing what I think happens when you ...
0
votes
1answer
167 views

How assembler coverts to machine code 1 and 0 [duplicate]

I know that assembler is the one which converts to machine code. So here in 8085 instruction set LDA has opcode "3A". My question is how assembler convert mnemonics to opcode and finally to machine ...
2
votes
3answers
212 views

Why is the next element of an int array stored 4 bytes after the previous one?

I have this small code: int* array_int = new int[10]; array_int[0] = 1; array_int[1] = 2; array_int[2] = 3; array_int[3] = 4; array_int[4] = 5; array_int[5] = 6; array_int[...
1
vote
3answers
196 views

Define C++ class in one or more files

When creating a C++ class what is best practice> Put the entire class definition and member functions in a header file Put the class definition and function declarations in the header file and put ...
2
votes
0answers
75 views

Using and designing asynchronous APIs with naturally synchronous parts

I've been programming for a long time, but very rarely with anything asynchronous (and not often with anything to do with multithreading, either). Mostly for the fun of it, I'm writing a program to ...
0
votes
1answer
106 views

Should smaller data types be used in intermediate code?

I often use smaller data types in structs/classes when it is needed in memory savings. I also use them in network/disk IO. My question is if intermediate code that use those objects with smaller data ...
-2
votes
1answer
174 views

Calling an entire script (in C) from another script (in C++)?

I am a very inexperienced programmer, so apologies if this is a stupid question to be asking. And similarly, if anyone answering could assume that I know basically nothing at all and treat me like an ...
1
vote
3answers
191 views

On a modern compiler, how do I intentionally code for 2s complement with wraparound?

I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, ...
0
votes
0answers
22 views

Creating and passing new object in parameter

I have a wrapper class which contains a smart pointer (unique) which can point to objects which are subclasses of State. Each subclass of State receives a reference to the wrapper class so that the ...