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

learn more… | top users | synonyms

1
vote
4answers
262 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
264 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 ...
2
votes
1answer
209 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
281 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
659 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
382 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
149 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
635 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
338 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
117 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 ...
4
votes
3answers
169 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
153 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
126 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 ...
16
votes
2answers
639 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
185 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
581 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
275 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
53 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
225 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
333 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
175 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
149 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
126 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
603 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
229 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
437 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
336 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
2answers
244 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
421 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
50 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() ...
3
votes
1answer
82 views

Access items of a container with a pattern

I've two C++ classes with a relation: a container class which has a list of items. For example a library has got many books. The classes are the library and the book. Now from the external world I ...
17
votes
11answers
6k views

Does C++ compiler remove/optimize useless parentheses?

Will the code int a = ((1 + 2) + 3); // Easy to read run slower than int a = 1 + 2 + 3; // (Barely) Not quite so easy to read or are modern compilers clever enough to remove/optimize "useless" ...
15
votes
1answer
582 views

How to effectively cooperate in a team having mixed background/mindset regarding OOP? [duplicate]

I've been recently assigned for a new high-performance C++ project (finance) together with 3 other guys who, like, me, refer to themselves as "primarily C/C++ programmers", meaning, all of us have ...
-2
votes
2answers
859 views

Is there a difference in the C++ language between Visual Studio and Code::Blocks? [closed]

I used to program C++ on Code::Blocks, but it's boring now. The view of Visual studio is that it's much better. Will it change anything? Or is it the same thing? Same syntax?
4
votes
1answer
590 views

How can I “inspect” C++ code?

For reference, I am a JavaScript developer learning C++. The browser is a pretty powerful debugger, and I can easily place a breakpoint in my code, hover over a variable or expression and get the ...
1
vote
1answer
2k views

C++ Web Development for REST API [closed]

I've been a C# developer for long time, focused on ASP MVC the most. Two years ago, basiclly due to the lower costs and ease of deployment/management I began to migrate my projects to linux using ...
21
votes
7answers
3k views

Writing in C for Performance? [closed]

I know I have quite frequently heard that C typically has a performance advantage over C++. I didn't really think anything else of it until I realized that MSVC doesn't even seem to support the newest ...
3
votes
1answer
155 views

Can the possibility of a data race be ignored in some cases? (while having concurrent threads) [duplicate]

I am programming a game engine as a hobby project, and I would like to separate physics and drawing into two separate threads. The position vectors of entities are subject to modifications by the ...
0
votes
3answers
307 views

Why std::allocators are not that popular? [closed]

With the latest trends about C and C++ applications, and with latest I mean the latest years, I was expecting to see std::allocators to be used way more frequently than what it really is. Modern ...
-3
votes
1answer
191 views

Is it possible to go back to a previous statement c++ [closed]

So I'm learning the basics with C++, and I've created a small text based shopping mall which asks the user if they'd like to buy an item. If the user responds with yes, or any variant of yes, it'll ...
7
votes
3answers
363 views

Object Identity and Mutability

I was reading a proposal for value types in Java, and I came across this sentence: "Object identity serves only to support mutability, where an object’s state can be mutated but remains the same ...
0
votes
1answer
158 views

Is ok to throw exception in normal code path which eliminate a possible programmer error? [duplicate]

I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception. But what happen ...
2
votes
1answer
157 views

How and when should I design a simple mark-up language parser? [closed]

I want to write a simple markup language with its rendering engine. First, I am not completely sure when I should try this... I am only 12... But I am competent in C++ having learned through the Web ...
0
votes
1answer
296 views

How to explain that catch(…) is wrong? [closed]

I have a problem: Now Microsoft has changed, and in respect with the C++ Standard, and starting from from Visual Studio 2005 now: Access Violation are not to be catched in catch(...) However, if ...
0
votes
1answer
113 views

Is it better to pass the whole object or use a setter?

Here is my initial code that I would like to modify by using strategy design pattern. class Bar { int a; int b; ... } Class Foo { Bar *bar; bool action1(){ // this function does a ...
0
votes
1answer
127 views

Traversing an AST using Visitors

I'm writing a compiler for a C-like language, and I'm looking for an elegant way to traverse my abstract syntax tree. I'm trying to implement the Visitor pattern, although I'm not convinced that I'm ...
0
votes
2answers
153 views

Rewriting code under BSD license

I am currently studding OpengGL with OpenGL Supebible 5th edition. I've found interested for me some C++ code that is distributed with the book (see also on google code). That code is under New BSD ...
0
votes
3answers
310 views

Understanding object-oriented programming: why is it important? [duplicate]

Just started learning about classes in C++ and I'm have trouble understanding why object orientated programming (OOP) is useful. I understand the syntax, how to use them etc. But I'm still confused ...