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

learn more… | top users | synonyms

3
votes
3answers
232 views

Data Oriented Design - impractical with more than 1-2 structure “members”?

The usual example of Data Oriented Design is with the Ball structure: struct Ball { float Radius; float XYZ[3]; }; and then they make some algorithm that iterates a std::vector<Ball> ...
2
votes
2answers
244 views

Code re-use in C++, via multiple inheritance or composition? Or…?

I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes. If you’re defining a hierarchy of abstract ...
2
votes
2answers
133 views

When does extracting methods from code stop to make sense? [duplicate]

I am currently studying the refactoring methods defined by Marting Fowler (http://refactoring.com/catalog/). He states a tip for replacing chunks of code by a single method that does that job. So ...
0
votes
4answers
620 views

Why would a C executable be smaller when compared to C++ executable

I'm trying to understand why the output file sizes are significantly different when using a C and a C++ compiler. I was writing a small hello world program in C and C++, I noticed that in C version, ...
0
votes
1answer
126 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 ...
1
vote
3answers
146 views

How to make a random-access archive of text files?

I wrote an application that tests the performance of evolutionary algorithms. This application performs a run of the algorithm which consists of several generations. The data which is produced by my ...
2
votes
2answers
258 views

What is a good C++ API Design for HW registers?

I am designing an API for a driver that manipulates HW. I have done the following: namespace HWRegister { //private: namespace Data { //accessible only within this namespace ...
1
vote
3answers
91 views

Setting global parameters: is this a reasonable use of const_cast and volatile?

I have a program that I run repeatedly with various parameter sets. Different parameters are used in different parts of the program (including different source files). The same parameter may also be ...
2
votes
3answers
259 views

Transitioning from Java & C to C++

I learned Java and I'm pretty competent programming in it. I also learned C recently. I looked at a comparison between Java and C++ and I like C++'s features like operator overloading and its speed. ...
1
vote
1answer
151 views

Where does `this` go in a x64 thiscall?

So I understand that thiscall doesn't really exist in x64 programming. However, I can't really find any definitive explanation as to where the this pointer is put to be passed to the callee. Is a x64 ...
3
votes
2answers
348 views

Why doesn't C++ allow you to take the address of a constructor?

Is there a specific reason that this would break the language conceptually or a specific reason that this is technically infeasible in some cases? The usage would be with new operator. Edit: I'm ...
1
vote
3answers
149 views

Is storing pointer (of new'd object) in static collection from object constructor a common idiom in C++

In code I am reviewing a common approach I see to storing objects (eg a socket client object), is use a static container to hold the objects. The objects are created by some helper function, eg like ...
6
votes
4answers
467 views

Split up large interfaces

I'm using a large interface with about 50 methods to access a database. The interface has been written by a colleague of mine. We discussed this: Me: 50 methods is too much. It's a code smell. ...
1
vote
3answers
183 views

Is heap fragmentation a problem in bare-metal arm with g++?

I am converting a project from C to mixed C/C++. It is going quite nice, and the new features are really lightening the work. The platform is an ARM SAM4, compiler is arm-none-eabi-g++. This is not a ...
1
vote
1answer
121 views

Subscript/assignment binary operator in C++

I was designing a kind of a parser when I thought that it would be nice to have an operator overload like this: operator[]=(subscipt_type s, rvalue_type val). For example we have a class: ...
0
votes
2answers
248 views

Usage of raw pointers

So from the top-voted answer to this question, it appears that using raw pointers for storage isn't frowned upon so much. However, then what is the point of a std::weak_ptr? I thought that storage was ...
2
votes
1answer
152 views

acceptance test driven development in c++

Was put on hold at stack overflow: hopefully it has value here. I want to use a BDD / TDD / ATDD approach in c++. However I really want to emphasize vertical slices of end to end functionality rather ...
0
votes
0answers
46 views

How would I do a vim-style character text editor in a graphical application?

There's a cool guitar tabbing application that I've used before where you can use the keyboard to move around a character grid. You can put any digit in any character cell. Here is an image: This ...
1
vote
4answers
239 views

Combinatorial explosion of interfaces: How many is too many?

I'm a relative newcomer to OOP, and I'm having a bit of trouble creating good designs when it comes to interfaces. Consider a class A with N public methods. There are a number of other classes, B, C, ...
3
votes
3answers
251 views

Genetic Algorithm new generation exponentially increasing

I'm programming Genetic Algorithm in C++ and after searching all kind of ways of doing GA'a operators (selection, crossover, mutation) I came up with a doubt. Let's say I have an initial population ...
3
votes
1answer
198 views

High-level description of how experimental C++ features are developed?

Herb Sutter in a video answers a question about the concepts proposal considered for C++11 and from his remarks it sounds like multiple groups offered prototype implementations but all of them left ...
0
votes
1answer
265 views

Algorithm to Copy data faster than windows default copy provider

I need an algorithm which can copy data(files/folder) from one place to another, faster than windows default copy/paste option. I'm working in vc++. Is there any algorithm by which I can do copy/paste ...
0
votes
1answer
459 views

Face Recognition(OpenCV) with MySQL and PHP

First of all I have asked this question on stackoverflow and got down vote for question being not belonging to the site. I am trying my luck se now(more suitable to se I guess) and I hope I will not ...
2
votes
4answers
368 views

In C++ Good reasons for NOT using symmetrical memory management (i.e. new and delete)

I try to learn C++ and programming in general. Currently I am studying open source with help of UML. Learning is my hobby and great one too. My understanding of memory allocation in C++ is that it ...
0
votes
2answers
142 views

Array of pointers in C++.

I am not understanding the output of this , #include <iostream> using namespace std; // pointers and arrays char ch1 = 'a' , ch2= 'b'; char ch3[6] = {'c', 'd', 'e', 'f', 'g' , 'h'}; char ...
1
vote
2answers
179 views

What is the concept behind writing a cancel operation in c++? [closed]

I'm attempting to write a cancel operation for a software download application. This application will first transfer the software to the device and then install the software on it. (These are givens ...
1
vote
1answer
401 views

Global variable in a Linux shared library

Suppose we have the following setup under Linux, .so library named "libcnt.so" and 3 user space apps: "app1", "app2", "app3". This library does 1 simple thing, it says to the app (app dynamically ...
3
votes
3answers
335 views

Purpose of building file using Make

I am trying to understand what is the purpose of making files using commands such as cmake .. and make, I have tried looking online but there is no concise explanation on its purpose that i could ...
2
votes
1answer
107 views

Improving the running time of Breadth First Search and Adjacency List creation

We are given an array of integers where all elements are between 0-9. have to start from the 1st position and reach end in minimum no of moves such that we can from an index i move 1 position back and ...
3
votes
3answers
164 views

Organization of DLL linked functions

This is a code organization question. I got my basic code working but when I expand it, it will be terrible. I have a DLL which I don't have a .lib for. Therefore I have to use the whole ...
3
votes
1answer
296 views

Use a template to get alternate behaviour?

Is this a bad practice? const int sId(int const id); // true/false it doesn't matter template<bool i> const int sId(int const id) { return this->id = id; } const int MCard::sId(int ...
0
votes
1answer
140 views

Syntax of passing lambda

Right now, I'm working on refactoring a program that calls its parts by polling to a more event-driven structure. I've created sched and task classes with the sced to become a base class of the ...
-1
votes
1answer
123 views

How to solve linear recurrences involving two functions?

Actually I came across a question in Dynamic Programming where we need to find the number of ways to tile a 2 X N area with tiles of given dimensions.. Here is the problem statement Now after a bit ...
15
votes
2answers
528 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 ...
2
votes
1answer
178 views

Is there a Design Pattern for preventing dangling references?

I was thinking about a design for custom handles. The thought is to prevent clients from copying around large objects. Now a regular handle class would probably suffice for that, but it doesn't solve ...
4
votes
1answer
570 views

Why are most GNU's software written in C [closed]

I am a Java developer, and I rarely write GUI program in C. However, I noticed that many GNU's projects, such as PSPP, R, Dia, etc., are written in C, instead of Java or C++. I personally don't mind ...
3
votes
1answer
239 views

How to maintain encapsulation with composition in C++?

I am designing a class Master that is composed from multiple other classes, A, Base, C and D. These four classes have absolutely no use outside of Master and are meant to split up its functionality ...
2
votes
1answer
51 views

Handling Types for Real and Complex Matrices in a BLAS Wrapper

I come from a C background and I'm now learning OOP with C++. As an exercise (so please don't just say "this already exists"), I want to implement a wrapper for BLAS that will let the user write ...
-2
votes
4answers
214 views

Benefits of porting C library to C++ [closed]

Say we take any C library such as libpng or libvorbis and convert it so that it compiles as C++ (only the minimum changes to make it compile as C++ code). Can the compiler do extra optimizations when ...
1
vote
2answers
323 views

“bug” in C++11 text by Stroustrup?

I found an apparent contradiction in the c++ text having to do with the result of the c_str() function operating on std:strings (in my copy, the definition and contradiction are on p1040). First it ...
1
vote
3answers
146 views

Use unnamed object to invoke method or not?

If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method? normal: TaxFileParser tax_parser(tax_file_name); auto content = ...
3
votes
1answer
135 views

How to store the file names, start offset and length while avoiding the issue of self imposed limits (lookup table) or having to scan the entire file?

I am attempting to learn more about C and it's descendants(C++ mainly). I have decided that I would like to create a "file system" of sorts. Not a particularly advanced one mind you but something to ...
0
votes
2answers
102 views

Extract all related class type aliasing and enum into one file or not

I have many models in my project, and some other classes just need the class declaration and pointer type aliasing. It does not need to know the class definition, so I don't want to include the model ...
2
votes
2answers
572 views

In C++ is casting to find bad pointers undefined behavior?

By accident I found that with a polymorphic type using dynamic_cast back to the derived class will throw a 'bad cast' error if the pointer is no longer valid. Is this undefined behavior or could this ...
0
votes
1answer
227 views

What language is better for working with databases? [closed]

I am going to develop a software that works with different databases and I'm considering whether to use .NET languages or C++. I've known that .NET features LINQ and ADO.NET but are there features ...
0
votes
4answers
351 views

Only functions without a class in cpp file! good design or not? [closed]

When I was going through the project on which I am working, I came across a cpp file, which has only functions and static variables.I was wondering why they have not put everything into a class! ...
1
vote
2answers
315 views

C++ raw pointers for storage

I'm seeing a lot of people say you should never use raw pointers. What about in the case where you store the raw pointer in a class but how they get populated is from getting the pointer of an object ...
1
vote
1answer
155 views

C++ returning references

Looking at making a GUI library for a game engine. I generally avoid pointers if I don't need them and in my below example I find that I don't and it works, but just curious if this design is ...
3
votes
4answers
412 views

Why do we put private member functions in headers?

The answer to why we put private member variables in C++ headers is that the size of the class must be known at points where instances are declared so that the compiler can generate code that ...
0
votes
1answer
45 views

NVI for virtual function implemented in every layer of a deep hierarchy

Suppose we have the following class hierarchy: class Object { public: virtual void update() { // Update position } }; class Rocket : public Object { public: virtual void update() ...