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

learn more… | top users | synonyms

-4
votes
0answers
28 views

Good c++ books for a non-programmer? [on hold]

I need a book that teaches c++ programming for someone who has never programmed before(a friend of mine). I'm aware that choosing c++ as a first language is difficult, but this guy is already ...
-3
votes
0answers
29 views

Examples of modern, well designed C++ projects that don't use object-orientation? [on hold]

Does anyone know of any open-source, well-designed and moderately modern C++ projects that do not use an Object-Oriented approach? It could be either done in a functional fashion, or in a more ...
1
vote
2answers
65 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 ...
0
votes
1answer
407 views

GUI code implementation for specific Window/Form class

Terminology Element/Form Element -> Fields such as text list, combo_boxes, push buttons, etc. Problem I have a program that is basically a fat client that interfaces into a system that keeps track ...
17
votes
5answers
3k views

Why do all <algorithm> functions take only ranges, not containers?

There are many useful functions in <algorithm>, but all of them operate on "sequences" - pairs of iterators. E.g., if I have a container and like to run std::accumulate on it, I need to write: ...
12
votes
7answers
325 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 ...
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 ...
6
votes
5answers
3k views

Alternate string formatting options in C++?

I'm looking at optimizing some string formatting code that's hit a lot in our code. We had been using ostringstream, and I converted the code to use sprintf (actually Microsoft's more secure ...
-1
votes
1answer
45 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 ...
2
votes
2answers
79 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 ...
5
votes
2answers
482 views

Is it possible to refactor inheritance to composition when virtual methods are called inside the base class?

Let's say I have a class called Country and two subclasses called AI and Player. The Country class has a number of virtual methods to allow player-specific or AI-specific behavior. I want to make it ...
22
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?
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 ...
16
votes
2answers
3k views

What's RAII? Examples?

Always when the term RAII is used, people are actually talking about deconstruction instead of initialisation. I think I have a basic understanding what it might mean but I'm not quite sure. Also: is ...
22
votes
3answers
3k views

C++ strongly typed typedef

I've been trying to think of a way of declaring strongly typed typedefs, to catch a certain class of bugs in the compilation stage. It's often the case that I'll typedef an int into several types of ...
0
votes
4answers
19k views

2 Dimensional Arrays in C++

I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif. I tested it out and i was amazed that it could give the programmer the ability to store ...
3
votes
3answers
194 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 ...
-3
votes
0answers
27 views

How to transfer signed integers with libusb? [closed]

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

C/C++ for algorithm development [closed]

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 [closed]

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
232 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, ...
0
votes
3answers
181 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 ...
15
votes
5answers
5k views

If a variable has getter and setter, should it be public?

I am an about to graduate Computer Science student so probably this is a stupid question. If I have a class with a variable that is private and the class have getter and setter for that variable. Why ...
2
votes
3answers
204 views

Disallow non-local storage of an object

I need to write a class in C++ that acquires a hardware resource and releases it again when it is destroyed. Basically that can be done in the constructor and destructor of the class. The difficulty ...
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 ...
3
votes
1answer
201 views

How can I use the “Non-Member Functions Improve Encapsulation” pattern from C#?

In 2000, Scott Meyers argued that non-member functions improve encapsulation. In C++, a non-member function is a C-style global function: ...
0
votes
2answers
73 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); ...
7
votes
3answers
9k views

What is meant by Scope of a variable?

I think of the scope of a variable as - "The scope of a particular variable is the range within a program's source code in which that variable is recognized by the compiler". That statement is ...
0
votes
1answer
511 views

Interface questions for using Command Pattern and Dependency Injection together

I have many projects that have essentially the same high level requirement: test all hardware on a device. Each device can have a different communication protocol, requires different test equipment 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
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 ...
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 ...
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
90 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
529 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??
6
votes
8answers
691 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 ...
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 ...
0
votes
2answers
1k views

Visual Studio c++ Windows forms? [closed]

I've been slacking off with learning how to program because I'm at my wits end trying to figure out the next step. I want to be able to create forms applications just to test random things and give ...
1
vote
2answers
120 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
139 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 ...
1
vote
0answers
113 views

Design of a datamodel in a OO way [closed]

I'm looking for some advice how to design a datamodel in OO way (C++ in special). My problem: The user input in runtime is a 1D matrix A = (a0,...,an). The program creates - on the basis of A - ...
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
3answers
527 views

Intersection of geometric entities

I was trying to design a small C++ geometric API for learning purposes, but came across a problem when dealing with intersections of geometric entities. For example, the intersection of a line and a ...
5
votes
2answers
2k views

Every function is a closure?

Wikipedia says, that closure - is a function, which has an access to variables, declared outside of the function. There is even an example: function startAt(x) function incrementBy(y) ...