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

learn more… | top users | synonyms

3
votes
2answers
240 views

How to stay DRY with return values

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
5
votes
3answers
271 views

How aggressively to change in-house smart pointer to unique_ptr?

I work on a large software product which, being over 20 years old, has a number of constructs which have been superseded by language updates. One of these is a home-rolled smart pointer template ...
4
votes
1answer
378 views

Why double colon instead of dot?

It is rumoured that early C++ implementations have had dot operator for namespace access. There is an opinion that the dot is more convenient that the modern double colon operator. What was the ...
1
vote
2answers
101 views

Catching exceptions from child process

I am looking for any info. (I know some C++ with win32 and C#) The Idea: The idea is to help a program with missing files load. In the end I wanted to see if I could have my program launch a simple ...
-2
votes
3answers
180 views

Is it possible to have private or protected objects in Java? Or are all objects considered public?

Is it possible to have private objects? For example, when you instantiate an object (classType object1 = new classType()), can that be private or protected or is it always public?
0
votes
1answer
142 views

Find if certain files have been added or removed in large directory structure

I have a larger directory structure (dir + sub directories) with files. It contains files of certain types. For one particular type (let's say with appendix .foo) I need to figure out if files have ...
1
vote
2answers
154 views

How to store state data when the data is related to another entity?

In order to increase the parallel-ability of my objects, I try to make them read-only and include only data that naturally belong to the entity. I have class Object { ... }; class Processor { ...
1
vote
1answer
96 views

Client-Server app architecture with custom communication protocol

I am working on Qt/QML/C++ based Client-Server software system with custom protocol. Now, in both projects inside QtCreator I have same header and implementation files inside both projects. What is ...
0
votes
5answers
253 views

Is there a better way to debug while avoiding getters/setters?

I'm thinking about how to debug better without using Getters/Setters. If it helps, I program using xcode. Many answers in Stack Exchange have argued against Getters/Setters for lack of encapsulation (...
2
votes
2answers
446 views

Should we “balance” the amount of codes between headers and cpp?

As far as I know, cpp usually contains far more codes than headers, mainly because they contain implementation details of functions instead of just one line of function definition. Here comes to my ...
13
votes
1answer
306 views

Should I add the source of libraries instead of linking to them?

I'm relatively new to C++, so I'm not sure how I should best handle small dependencies (e.g., a scripting language, or a JSON/YAML/XML Parser). Should I create separate projects and link them as ...
8
votes
5answers
548 views

Is it correct to say that a variable is an instance of a data type?

(that can change its value over the course of the program) Or is 'instance of something' strictly related to classes and objects? If so, how would you define the concept of 'variable' when it comes ...
1
vote
3answers
419 views

Which languages allow to mix its source code with C++ source code?

I have read that there are languages other than C++ that can also compile standard C++ source code too (Objective C++ can do this). Which other languages for Windows and Mac OS are there, that support ...
7
votes
1answer
91 views

Visitor Pattern, replacing objects

I have a program that translates a DSL to C++, which uses a Visitor pattern on the intermediate representation. I quite often need to replace the currently processed node with one of a different type ...
1
vote
0answers
82 views

How to structure enum data to achieve the desired effect

I'm making a framework for building simple html websites for an embedded system and I want to make it bulletproof in a way that a user can't make mistakes in building the html document. As I've ...
0
votes
2answers
146 views

C++ class vs function header file

I'm using C++ for implementing a project that requires to import a file once. All the data in this file needs to brought in memory as key value pairs, but only when the file is imported. Since this ...
5
votes
1answer
115 views

Algorithm to find span intersections in a sorted set

I have a set of items strictly ordered on time. Each item can either be single (no Next, no Previous) or part of a span (with either 1 or 2 further endpoints). For example in the picture A is part ...
3
votes
4answers
238 views

Is Template Pattern a good way to implement DRY?

Here is my problem: I have and class structure like this: class Base { private: SomeType something; bool isSomeValue; public: virtual void myMethod() = 0; }...
3
votes
1answer
142 views

Unique pointer initialisation

What is the correct initialisation of a smart pointer? std::unique_ptr<Class> ptr(std::make_unique<Class>()); or std::unique_ptr<Class> ptr = std::make_unique<Class>(); ...
3
votes
1answer
98 views

How do you manage your OpenCL source?

I am having a hard time deciding how I should manage my OpenCL source code so that my program can compile it at runtime. There seem to be two many strategies. You can create them in you C source as ...
28
votes
1answer
2k views

How does the C++ standards committee test their design ideas?

Does the C++ committee test their new design specifications with some sort of prototype compiler before releasing a new standard? Or do they release a standard which is, in effect, only theoretical ...
3
votes
1answer
527 views

In my situation, how could I learn to program without a mentor? [closed]

So my problem may be relatively rare, at least the majority of the "how to learn to code" questions I've come across deal with a lack of fundamental understanding of computers or languages. I'm fluent ...
0
votes
1answer
401 views

Recommendations to organize code changes in GIT

I'm looking for an advice reflecting my point of view. First, I will explain my point of view. My point of view I'm working in a big company as a C++ developer, we are using GIT. I'm going to make a ...
1
vote
1answer
98 views

Analyzing a C++ library with a diagram [closed]

When I want to read an entire library in C++ I start with class A. Then I realize class A is using function B. Function B is using class C and C2 and class C uses class D. I am aware that this ...
2
votes
0answers
136 views

Speed: Named Shared Memory vs Memory Mapped File vs Normal Memory

Let's say I have a server, where clients who connect are constantly updating their inventory. I could simply save the changes in to the database after an item has been updated, or I could update the ...
0
votes
1answer
169 views

Kernel facilities needed for C++

I'm working on a kernel for a proprietary embeded system. I've had no issues but I'd like to expand its capabilities directly. I made it run C. I did so pretty much by giving my kernel a stack. My ...
5
votes
4answers
324 views

Why is there a need for reference parameters in C++?

We've been learning about reference parameters in my Intro to Programming class. I understand perfectly that reference parameters give you access to the place where an argument is held in memory, ...
2
votes
2answers
160 views

C++ object references vs. lookup

Let's assume there are 2 classes: Country and City. Both of them have names, so a map would suit as conainer map<std::string, Country> countries; In the country class there is a similar map ...
2
votes
1answer
100 views

Best way to use a C++ style api from a C style file compiled in C++

I am working a in a Telecom company. We have some code generation tools that generate C style files based on a MIB definition. We compile them with C++ though. It boils down to the fact that these ...
1
vote
1answer
137 views

Async I/O operations - proper way to avoid deleting object

Using async I/O operations from boost::asio I often need shared pointers (and enable_shared_from_this and shared_from_this in callbacks) to avoid deleting objects too early. I think that it could be ...
1
vote
1answer
168 views

In C, are large 'pointer chains' bad for performance or code cleanliness?

The following for example: i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps); It has a large amount of nested structs/unions. Is this generally frowned upon in code ...
0
votes
2answers
115 views

The way to implement a configurable (at run-time) default style

I am coding a visualizer of graph algorithms. Each vertex of the graph has a style (color, size etc.). As long as the algorithm has done nothing to a vertex, that vertex has a default style. The ...
4
votes
1answer
215 views

How to Structure Simple C++ projects for TDD

I am introducing Google Test into our development environment at work, and would like to encourage a TDD mindset, making this as accessible as possible for new developers to start using. I am looking ...
4
votes
2answers
101 views

Accessing members of a set by one of their properties

I often find myself in the situation where an object contains a set of objects, and I want to access one of these objects based on one of its properties. How I currently do this in C++ is to put ...
1
vote
2answers
127 views

C++ Parametric Polymorphism

In the wikipedia article on Parametric Polymorphism, is the following commentary on C++. Can anyone explain what it's referring to when talking about "ad hoc aspects"? (I think it needs a citation)....
4
votes
2answers
328 views

Designing an in-memory table in C++

I'm evaluating my options to structure an in-memory database and I have a few ideas of how to implement it. I would like to know your opinion of what the best design choice is. I have a column class ...
7
votes
2answers
257 views

Object reading from file, violation of SRP?

I am writing a physics simulation program in C++. I am a novice in OOP and C++. In my program, several objects need to be initialized based on data from an input file. For example, an imaginary ...
2
votes
0answers
44 views

How to architect rule matching with multiple conditionals and outcomes

I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be ...
-4
votes
2answers
133 views

Repeating a Particular Iteration of For-Loop [closed]

I want to repeat a particular iteration of a for loop twice. The way I am doing it is that I am decrementing the index in that particular iteration. for(int i = 0; i < 100; i++) { switch(state)...
3
votes
1answer
320 views

Bad c++ code design? [closed]

This is bothering me a long time. I feel like I am doing mistakes on the code design relative to the performance. I never had any teacher to indicate my mistakes so its hard to me to make it right in ...
5
votes
4answers
526 views

Is it a good idea to document every assumption in code, even if it goes against the standard of the language?

For instance, would this c++ function be a good idea? void doSomething(not_nullptr<MyType> arg) { // stuff } With not_tullptr being a template wrapper for pointers, that will throw an ...
0
votes
1answer
74 views

Blocking queue for token based synchronization

I'm currently looking for a good solution for the following use-case in C++ (preferably C++11 or C++14): The program is running a server with a TCP connection. Other clients can connect at any time ...
2
votes
1answer
137 views

What is an appropriate pattern for handling a queue of network events in C++?

I'm writing an application that sends and receives messages over the network and pushes them into a std::deque queue. and I'm looking for the appropriate programming pattern to handle all of the ...
2
votes
2answers
128 views

Abstraction on Iterator Pattern?

Recently, I had the task to implement a research project where I had to read an XML file. XML file contained a list of messages that I had to send to some other system on a specific port. Each message ...
0
votes
4answers
419 views

Are there reasons to assign NULL instead of 0 to non-pointer variables?

Assigning variables with values during definition is a good practice. A common practice is to assign variables with 0 and pointers with NULL. int p = NULL; // instead of int p = 0; int *ptr ...
-1
votes
1answer
112 views

SDL_net how to get the UDP remote address? [closed]

I have a problem with the tcp and udp synchronization. On the server it accepted the tcp connection with the: SDLNet_TCP_Accept(); But now I need to know how to get the remote address of the ...
2
votes
2answers
310 views

Error handling in C++

So, in the recent weeks I delved into C++ programming, and I programmed some things in SDL. Doing so, you always have to deal with a lot of (ugly) C++ code, which looks more like C than C++. One thing ...
3
votes
4answers
148 views

Low-level error handling

I am working with some low-level (by that I mean code that can't use C++ exceptions and/or the standard library) code that makes heavy use of classes. Basically, every class contains a bool initialize(...
-1
votes
3answers
186 views

How are expressions evaluated in Turbo C++?

I was reading about casts in c++ and got confused about how are the expressions actually evaluated. Consider the following code in which var is of type int and after the expression var = (var*10)/10 ...
4
votes
2answers
155 views

Free-standing function calling a state-changing member function — a bad practice?

Item 23 of Effective C++ (3rd edition) by Scott Meyers is titled: "Prefer non-member non-friend functions to member functions". I understood that the intention of Scott was that, whenever a function ...