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

learn more… | top users | synonyms

1
vote
2answers
29 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 ...
-1
votes
0answers
16 views

Error in c++ code -Templates [on hold]

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
62 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 ...
-4
votes
0answers
32 views

Windows custom lockscreen program [on hold]

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 ...
-1
votes
0answers
78 views

How to compare numbers in a file? [on hold]

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 ...
2
votes
1answer
136 views

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

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 ...
-4
votes
0answers
57 views

Where can I find a compiler [on hold]

and tried looking for a c compiler. I have tried GCC which is now GNU I think now, but did not seem to work is there any advise people can give to some just looking to start out thanks Hayden
0
votes
0answers
22 views

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

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 ...
0
votes
0answers
47 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 [on hold]

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
26 views

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

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
141 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 ...
-1
votes
0answers
24 views

Dijkstra algorithm with pair [closed]

int dijkstra(){ memset(visited,false,sizeof visited); priority_queue< pair<int, int> > Q; for(int i = 0;i < A;++i) Q.push(make_pair(0,X[i])); while(!Q.empty()){ pair<int, ...
-1
votes
0answers
39 views

Is there any way of doing if/while assignment in Visual Basic? [closed]

For example, in C/C++, you can do the following: #include <iostream> #include <conio.h> int main() { char c; while ((c = getch()) == 'f') { std::cout ...
0
votes
0answers
72 views

What's stopping “After Effects- like” apps from being developed in the browser given ASM.js [closed]

Given asm.js are there any significant technical reasons stopping an app like adobe's after effects in the browser? I'm aware that it would probably be a massive task, but from a purely technical ...
2
votes
1answer
188 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
95 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
194 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
141 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
53 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
300 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
54 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
758 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
66 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
178 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
157 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
93 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
48 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
136 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
68 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
110 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
179 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
106 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
139 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
172 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
61 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 ...
1
vote
1answer
84 views

What's the quickest and most maintainable way to implement SQL querying of disparate C++ variables?

I've recently joined a team working on radar observations. The team has access to a repository of software (written in C++) used for dealing with these observations, but their work is focused towards ...
2
votes
1answer
49 views

How does condition_variable::notify_one() choose which thread to unblock?

notify_one() of C++ 11 thread library is used to unblock one of the waiting threads. How does it choose which thread to unblock? To begin with, I tried googling but could not find any appropriate ...
1
vote
1answer
76 views

Templating a member name

I'm writing a library that provides graphs for search algorithms. Usually you want to rank nodes using a priority queue. Normally you want to search for an specific node in the queue and lower its ...
1
vote
1answer
209 views

Inserting C++ code into C [closed]

What I need to do before inserting C++ code into C, and how to do it? Are there any examples to show me how this can be done. I have a good knowledge of C, but never mixed those two. Thanks for the ...
1
vote
0answers
95 views

Software Design, Generic Programming, Physical Devices, and Algorithms in C++ [closed]

I often have data that in some contexts I want to handle uniformly, but in other contexts I wish to differentiate it. For example, I could have a vector that is series of angles or a series of ...
5
votes
3answers
323 views

Idiomaticy of macros in C++

Macros are considered a good thing by one and evil by another. Is there a rule of thumb when to and when not to use macros in C++? When are macros idiomatic and when should they be avoided?
2
votes
2answers
186 views

How do I make this functional DSL written in an imperative language more efficient?

Suppose I create a simple functional Domain-specific language (DSL) using an imperative language, in this case C++. Here is a simple implementation of a DSL that can has the notion of a simple value ...