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

learn more… | top users | synonyms

0
votes
0answers
11 views

Left & right justification on the same line in console output

This is my first question on here, so I hope I'm being clear enough. I'm finishing up a little programming project for a class at the moment. I'm done with all of the actual requirements for the ...
1
vote
3answers
44 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
4answers
88 views

Is it ever overkill creating classes/objects?

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
35 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 ...
3
votes
0answers
42 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 ...
-3
votes
0answers
22 views

Segment sieve of Eratosthenes code [on hold]

I got this code to print prime number between m and n and while doing its dry run ,i observed that even if prime is not set to be 1 for composite 4 it gives same result int main(int argc, char** ...
3
votes
0answers
51 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
0answers
24 views

How to use fftw in Qt [on hold]

Could anyone explain how to use the library fftw 3.3.4 in Qt5.4.2, please? I have looked for some examples on the internet and followed them. But it didn't seem worked to me. Thanks a lot for any ...
3
votes
2answers
122 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 ...
-4
votes
2answers
156 views

Is it possible to learn C++ on the fly? [on hold]

I am reading books and doing the examples that the book has to offer. Often times, I find myself getting bored b/c t.b.h it's basically stuff that doesn't really interest me much. Don't get me wrong, ...
0
votes
3answers
102 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
160 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 ...
-2
votes
0answers
22 views

Error in c++ code -Templates [closed]

I get an error in this following code.where is the error in this following code.and please explain a bit. template<class T1,class T2> T1& MinMax(T1 t1,T2 t2) ...
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
72 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 ...
-5
votes
0answers
42 views

Windows custom lockscreen program [closed]

I'd like to create a windows application that locks my screen, I want the program to have the same functionality as this program but I want to add functionality to it so I can play custom sounds and ...
-2
votes
0answers
87 views

How to compare numbers in a file? [closed]

What I would have to do to search a file (file.txt for example), and compare its values with the ones I'm asking the user to input. There will be numbers in the file already(production orders) and i ...
1
vote
1answer
144 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 ...
0
votes
0answers
23 views

What is prerequisite for Algorithm and Data Structure Analysis and Designing [closed]

I want to learn Programming, So I want to start this learning program with studying of the Introduction to algorithms book. I'm familiar with C, C++ and ASM Language a little bit, but I can't write ...
1
vote
0answers
55 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 ...
-1
votes
0answers
24 views

Best use of Winpcap [closed]

I just need to know the best/most efficient way to use winpcap to monitor 5 different tcp ports while another program is running displaying the data etc. I was using a thread for each port with a ...
-3
votes
0answers
27 views

How to compile Selenium on Debian Jessie, failing on ibus [closed]

When I compile Selenium on Debian Jessie, it gives me this output. I have ibus lib installed. I think that I use different version. I am right, how can I solve it? If you need to provide any ...
2
votes
2answers
159 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
196 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
98 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 ...
0
votes
4answers
199 views

How to write procedural code in an object oriented language?

I recently started working in domain of mesh generation . My programs usually contains large chunks of procedural code consisting of several phases. Eg. class MeshAlgo1 { /* A very long function ...
-4
votes
0answers
22 views

My code compiles, executes, but crashes for certain inputs [migrated]

I am trying to get the length of longest common subsequence for two strings. It works for most of the inputs but it crashes for the input specified. The code is as follows: #include <cmath> ...
0
votes
2answers
146 views

Are private members useful anymore? [duplicate]

Watchpoints and data break points make it possible to watch the changes of a value in memory in many languages. Much of the justification I have seen for getters and setters and private variables ...
9
votes
4answers
2k views

rand() gives same numbers again for a small range

I'm trying to make sort of a game where I have a a grid of 20x20 and I display a player (P), a target (T) and three enemies (X). All these have an X and a Y coordinate which are assigned using rand(). ...
1
vote
0answers
57 views

Data sync local LevelDB store with server? [closed]

I'm building a cross platform application in C++. I need to have local JSON data storage that is syncable to a server. LevelDB seems like it could fit the bill. There is a Node module ...
2
votes
0answers
47 views

Should the order of definitions correspond to the order of declarations in header/source files? [closed]

If my header looks like this: class foo { public: foo(); ~foo(); QString b(); QString c(); QString a(); void setB(QString s); void setC(QString s); void ...
7
votes
2answers
306 views

Const C++ DRY Strategies

For avoiding non-trivial C++ const related duplication, are there cases where const_cast would work but a private const function returning non-const wouldn't? In Scott Meyers' Effective C++ item 3, ...
2
votes
2answers
55 views

Reading using non-blocking IO on a fd asynchronously in C++ (moving from Node.js)

I'm trying to switch my brain from Node.js/Objective-C iOS programming to C++ programming, and it's a little bit taxing. Node.js and Objective-C with iOS do not have a run loop that I am supposed to ...
5
votes
2answers
762 views

Is there a standard way to indicate that a function returns a new pointer?

Sometimes I want to delegate the construction of objects that a class owns to a separate function. Something like Vertex* new_vertex(const Options& options) { // do stuff... return new ...
0
votes
0answers
67 views

Why are datatypes different in terms of bit size based on complier, and OS used

I was reading a tutorial on C++ as I am new to programming, and I was wondering why the sizeof operator gives different output depending on what you're programming with.
4
votes
2answers
179 views

Rust-style error handling in C++

I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can ...
3
votes
1answer
159 views

When writing a math library, will operator overloading maintain OOP?

I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just ...
0
votes
1answer
96 views

Modular programming practices

As I start to code more and more, for example in C++, I tend to also want to learn more about the accepted standards for code. I'm trying to code a chess engine right now, but I'm unsure how to treat ...
0
votes
0answers
56 views

c++ constructor and operator problem [migrated]

I have a problem with constructor and assignment operator. This is my code: class Class { private: double number1; double number2; public: Class(double, double); ...
4
votes
0answers
53 views

Directory organization of a CMake (C++) repository containing several projects

I would like some advises on the organization of a set of related but independent C++ projects stored in a single (git) repository. The projects use CMake. For a simplified example we imagine 2 ...
2
votes
1answer
139 views

Does applying a prefix to member variables make sense in C? [closed]

//C code struct Foo{ int m_nVar; } struct Foo f; f.m_nVar = 0; Despite the fact that many consider Hungarian Notation an anti-pattern, I am working in a code base that enforces it. 90% ...
3
votes
1answer
70 views

Design approach to outsourcing a socket in an own thread

I want to extend an existing server written in C++ to be able to communicate with an other server over websockets (e.g. logging or user authorisation purposes). All examples (including the very well ...
3
votes
2answers
111 views

C++ using shared_ptr with API [closed]

I'm building a library that generates a couple of types of objects that can be used by user code and the library. To keep track of these objects, I'd like to use shared_ptr's, so I can build in some ...
4
votes
3answers
180 views

Strategy for fixing signed/unsigned warnings

I'm working on obtaining a clean compile with -Wsign-conversion for existing library code. The library is 25 years old or so. Eventually, this higher bar will be a security gate, and all check-ins ...
-3
votes
0answers
39 views

How to get/set value for pixels C++ SDL [migrated]

I'm making a basic 2D rendering engine in C++ with the help of SDL but I can't find the answer to one question: how do you get/set values for pixels without having to access each individual pixel? ...
3
votes
2answers
110 views

In C++, when should I use final in virtual method declaration?

I know that final keyword is used to prevent virtual method from being overriden by derived classes. However, I can't find any useful example when I should really use final keyword with virtual ...
0
votes
2answers
140 views

bool accepts int literals, char literals, string literals - why?

Programming: Practices and Principles - Bjarne Stroustrup Drill in Ch 5 - Errors He wants us to correct the code: boo c = "fool"<s; On correcting boo to bool, this is a comparison, so that's ...
-1
votes
2answers
177 views

How to debug a program after it appears to fix itself [closed]

While chasing a segfault around a complicated and grouchy c++ program I added several //comments and cout statements, but no 'actual' code. Then, suddenly, for no apparent reason the segfault ...
-1
votes
1answer
62 views

execute selection in console in C++ like python or R language [closed]

I am started to learn C++ using as IDLE Clion of jetbrain company. Normally using the IDLE of Python (i.e., Pycharm of Jetbrain) or R project i am able to execute selection in console line-by-line my ...