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

learn more… | top users | synonyms

0
votes
1answer
11 views

const reference and const pointer. How do they work?

I read a post about how const storage works. How does const storage work? (Item 2, Scott Myers Effective C++) This says that each segment has separate section of write protected memory and const ...
-2
votes
0answers
17 views

Lead-lag controller implementation on PIXHAWK [on hold]

I am trying to implement a lead lag control strategy for a quadrotor. I ma running into issues of writing the controller structure in a c++ format using difference equation. Any ideas and suggestions ...
-1
votes
0answers
17 views

How to implement password protection functionality to a windows driver?

Nowadays, I am working on programming a windows driver of my printer I want to implement a functionality that requires password after printing 100 pages . After every 100 prints it should ask for a ...
0
votes
0answers
26 views

Why does my c++ code run fine on Windows 7 but crashes on Windows 8? [migrated]

Ok, I added the following code to a mod menu for a game and everything works fine for me in Windows 7. But when I send it to my friend on Windows 8, he tries to select a button (which calls the ...
2
votes
2answers
77 views

Blocking function call with asynchronous content

I am sure that this is a common design pattern, but I seem to have a blind-spot. I have a requirement that the function call from Application to Service be blocking, but service needs to do ...
12
votes
7answers
300 views

When NOT to use virtual destructors?

I believed I searched many times about virtual destructors, most mention the purpose of virtual destructors, and why you need virtual destructors. Also I think in most cases destructors need to be ...
-1
votes
1answer
36 views

Qt connection Sql Server (universal connection string)

I am developing a software to connect to sql server. The problem is, ¿i don't know wich sql server is used?, and my question is ¿if exist a universal connection String?. I read many cases and in ...
0
votes
0answers
82 views

Member vs free function [duplicate]

I've read similiar topics and also the following great article: http://www.gotw.ca/publications/mill02.htm I'm still not quite sure how to apply it though. Basically I have a class that is an ...
21
votes
1answer
2k views

Why does C++ not have a “pure” keyword for virtual functions?

I have always wondered why we code virtual void MyFunction() = 0; and not pure virtual void MyFunction(); Is there a reference for the basis of this decision?
-3
votes
0answers
26 views

How to transfer signed integers with libusb? [on hold]

I want to communicate with an arduino and sent integers it. I code this program in C++. I initialy used bulk_transfer(), but it sends only 1 byte char data. I want to send signed integers. The ...
3
votes
3answers
191 views

Is this a good method to create class hierarchies?

Is it a good design to store the type of the object in the base class as an enum? For example, consider the following hierarchy Expr --Unary --Binary --Const ----Int ----Float How to represent the ...
0
votes
0answers
136 views

C/C++ for algorithm development [on hold]

I developed an algorithm and prototyped it in python. Now I need a high performance executable. I've never programmed in C/C++, but know they're the right tools for the job. I'd rather do it in C ...
-1
votes
0answers
35 views

Tcp server language choice [on hold]

Is there any reason to use a specific programming language for TCP server programming? Or java, c# can achieve same as c++ without any noticeable performance loss?
2
votes
2answers
147 views

Is there any advantage to c-style bit manipulation over std::bitset?

I work almost exclusively in c++11/14, and usually cringe when I see code like this: std::int64_t mArray; mArray |= someMask << 1; This is just an example; I'm talking about bit-wise ...
0
votes
3answers
231 views

What arguments are there to use a coding style for each distinct language? [duplicate]

I recently had a discussion about our coding style for C# projects. Two things in particular were very hard to agree upon. Method Naming C# has the de-facto standard of naming (at least public, ...
2
votes
1answer
120 views

Does the LGPL apply if I rewrite a portion of JasperReports in C++?

I would like to rewrite a portion of the JasperReports library in C++. The library will read from the same XML format used by JasperReports. If I integrate this C++ library to my proprietary ...
0
votes
3answers
178 views

Is there a use for non-const reference parameters?

Given a function like: void do_stuff( Thing & thing ) { // at this point, I can inadvertently or purposefully change thing } Is there a reason to purposefully change thing? Changing thing ...
0
votes
2answers
72 views

Should I set values using the return or by giving a reference?

Suppose I have a mouse position watcher, which should let the user extract the mouse position. Should the mouse position be set in the method and returned: Mouse_Position ...
3
votes
1answer
253 views

In C++, why does the main function use 'char *argv[]'?

I was wondering why C++ uses the following function prototype for the main() function: int main(int argc, char *argv[]); instead of something like: int main(std::vector<std::string> argv); ...
-3
votes
0answers
46 views

C++ or Python: Best investment for a Medic/Software developer who wants to do complex medical image analysis [closed]

I am an intermediate programmer who uses RoR and previously PHP to create web applications to aid my clinical research - I am a radiologist. I am trying to develop some image processing tools to ...
1
vote
1answer
90 views

A little confused with virtual functions

Please see the following code: #include<iostream.h> #include<string.h> class father { char fname[20]; public: father() { strcpy(fname,"eshwarappa"); ...
0
votes
0answers
46 views

data structure with best match lookup

Let me explain my question with one example: I have the following structs: struct Box{ unsigned char color; unsigned double width; unsigned double height; unsigned double weight; }; struct ...
0
votes
1answer
58 views

How Do I Create A Module* For A Class That Relies On Another Module?

*I'm using "Module" to mean some extension of a class, either through inheritance or composition. Say I have one of the following declarations of an Entity: using EUnit = int; class Entity : /*With ...
2
votes
1answer
69 views

C++: Make classes immutable or compatible with STL containers

Making types immutable is often desireable, especially for multi-threaded applications. There's no need to worry about concurrent access and no need for any synchronization. The common STL containers ...
1
vote
2answers
106 views

“Sweep” a vector of pointers

I'm using a vector to store pointers to objects. In some cases I destroy one or more of these objects (setting the vector spaces to NULL after each delete call), which are externally selected: for ...
0
votes
0answers
5 views

Undefined reference error [migrated]

I know that there are a lot of questions about undefined reference out there, but I couldn't find any that is like my case, probably because I am new to C++. I am developing a little project ...
-1
votes
0answers
17 views

Implement settings, common practice? [migrated]

Assume I save my settings of a widget with QSettings. How is QSettings meant to be used? As a member of my widget, accessed everytime one of the settings is used, or created and used once on widget ...
0
votes
1answer
87 views

AST processing and usefulness of visitor pattern

I know the visitor pattern is typically used to traverse a hierarchy of heterogeneous objects (inheriting a same abstract object) and dissociate the processing of these objects from the data within ...
2
votes
2answers
528 views

When and why should a destructor be declared as virtual?

As in class TestA { TestA(); virtual ~TestA(); } So why and when should the destructor for TestA be virtual??
2
votes
1answer
84 views

Including standard library headers only once across multiple program headers

I am writing a program with multiple headers and code files, as so: message.h message.cpp option.h option.cpp main.cpp message.h includes option.h as message.cpp requires the definition of the ...
2
votes
1answer
207 views

Refactoring code with just a few lines different

I have two for loops in a function which look like these: for (int i=0; i < MAX; ++i) { identical_lines identical_lines identical_lines first_for_specific_line identical_lines ...
1
vote
2answers
119 views

Is returning a reference to inside a private vector bad practice?

I have the following trimmed class: #include <vector> #include "Tile.h" class Board { std::vector<Tile> boardArr; // VVV Bad Practice? Safe? Tile& getTileAt(unsigned ...
2
votes
2answers
138 views

Alternative to using getters/setters in a simple class

I'm writing a minesweeper game with curses. To represent each tile, I wrote small Tile class that contains information about the possible state of each tile (whether or not it's flagged, whether or ...
2
votes
0answers
57 views

Heavy-duty use of C++ initializer_lists of containers [closed]

I've proposed and developed an optimization bringing move semantics to std::initializer_list. It seems like a slam dunk, but some on the committee saw the proposal as a waste of time, never mind ...
4
votes
1answer
228 views

How does modulus work?

I am not asking asking how the mathematical concept of modulus works, or how 20 % 3 == 2 I understand this fine. I'm more curious how the compiler/interpreter determines this. I can think of a very ...
-1
votes
0answers
21 views

Using Command Line Arguments to Choose a Datatype? [migrated]

Basically, based on whether a user inputs a 0 or 1 as a command line argument, I want my data class to either have a vector or an array (static) as its data member. I don't believe you can add if ...
0
votes
2answers
138 views

Style question: To use overloaded version or not?

Let's say I had an operator() overload that made temp_.matrix[k][j] and temp_(k+1, j+1) equivalent. In my class functions (where matrix belongs), would it be better to have if (temp_.matrix[k][j] == ...
-1
votes
0answers
27 views

how to create a char array in c++? [migrated]

I am trying to create a pointer to a char and pass it to function as a char*. here is my code to define the char array it seems the compiler does not recognize the end of the string because the ...
4
votes
4answers
256 views

What makes a program cross-platform or not?

I have fairly basic programming experience with Java and I've tried C++ and Python. While it makes sense for Java, the basic programs I've written in C++ have run just fine on Windows and OS X. I've ...
0
votes
0answers
38 views

Difficulty designing my EventHandler class that uses a callback to handle key-presses

I wrote an EventHandler class that takes a std::function<void(char)>, and a std::vector<char> of chars (representing keys). If a key in the vector is pressed, the call-back is executed ...
-2
votes
0answers
25 views

Addition and Subtraction giving incorrect results [migrated]

I made a simple program to add and subtract the given numbers. Let's say the 2 numbers give were 5 and 5. It would print 5 + 5 = 10 and 5 - 5 = 0. Right now I'm not sure what's wrong. I might need a ...
-2
votes
0answers
59 views

The correct way to use a for loop in an array C++ [migrated]

I'm having some trouble with a homework assignment dealing with Arrays. I have already read all the text from class (which didn't help me at all), looked up several tutorials on arrays, and searched ...
-2
votes
0answers
16 views

Using getline() with parameters to read through a file and extract specific information? [migrated]

I'm programming a c++ console application for school and I need to read through a .txt file to extract specific informations to use them in classes. For example, here is a portion of the txt file : ...
0
votes
3answers
190 views

Compile-time vs. run-time configuration

I'm starting new project and need to decide on how to handle configuration. I recently run into suckless project. While it has its own issues, I really liked its approach to configuration - just a ...
6
votes
2answers
209 views

Static console object or dependency injection?

For a current project I have created a Console class which wraps up C++'s usual cout, writes output to a file or uses Console::WriteLine depending on the environment. Currently I've setup my code base ...
1
vote
1answer
139 views

Are there real world examples demonstrating reasonable performance improvement by using move semantics?

(I've asked a similar question on SO but unfortunately it might not be proper, so I also put here; please kindly point out if you think it's a duplicate.) I've heard many words about the move ...
-1
votes
2answers
173 views

Mermaid problem (OOP) [closed]

A Mermaid is half fish and half human. It has upper human body and lower fish body. When under water its upper part swims like a human while its lower part swims like a fish. Please explain how can it ...
2
votes
3answers
351 views

In C++, should I ever declare a local variable in the corresponding header?

So for example, I create a class with two functions: foo.h class foo { public: foo(); void bar(); void ey(); bool m_memberBool; bool localBool; // ??? Should I put this here? }; ...
-1
votes
1answer
50 views

One symbol - one meaning?

It's well known recomendations that: 1) class or function should have one responsibility 2) variable should not be reused in different contexts We can generalize this recomendations to general ...
6
votes
8answers
690 views

Structuring Procedural vs OO code

I have spent the vast majority of my programming career using Java and very OO based C++. I am really interested in learning to think more procedurally, so I have been starting to do some practice ...