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

learn more… | top users | synonyms

0
votes
1answer
35 views

Tips for understanding big project fast?

I've got a job and many new things to be learned. The first thing is to understand big project, writtened mostly in C++, using Visual Studio. So, I see a statement, and I want to find its definition. ...
0
votes
0answers
29 views

Tracing and visualizing trace on a timeline

I am working on a c++ library, which performs frequent communication with a piece of hardware. I need a way to instrument my code with tracepoints, that I can afterwards visualize the execution of on ...
0
votes
0answers
4 views

From data file to Multi-Dimensional vector problems [migrated]

I am trying to write a "text adventure" engine that runs off of text and data files. I understand the concepts of arrays and multidimensional arrays, but know they cause memory leaks and not ...
-2
votes
1answer
45 views

Unexpected compilation error [on hold]

I wrote this. doesn't matter what am I supposed to do with it. It just doesn't complie! Using G++ 4.9 In the line which I insert data into the set I get error! commenting out that line will solve the ...
-3
votes
0answers
54 views

I want to build a software with C++, book list is needed [on hold]

Can you tell me where i can start from, I have already learned c++. I want to build a software with C++, book list is needed.
11
votes
7answers
13k views

What is the point of using lists over vectors, in C++?

I've run 3 different experiments involving C++ lists and vectors. Those with vectors proved more efficient, even when a lot of insertions in the middle were involved. Hence the question: in which ...
0
votes
2answers
1k views

efficient way to count number of swaps in insertion sort

I am browsing some online coding challenge online and got struck somewhere . Objective of program is to find maximum number of swaps required in sorting an array via insertion sort in efficient time ...
-4
votes
1answer
77 views

In my code everything works fine, when i debug i always get a 0 for smallest. why? [on hold]

NOTE I JUST STARTED LEARNING C++. THIS IS SCHOOL WORK AND WOULD APPRECIATE IT IF SOMEONE TAUGHT ME INSTEAD OF GIVING THE ANSWER. int a = 0; int b = 0; int c = 0; int sum = 0; int average = 0; int ...
0
votes
1answer
85 views

How shall I handle event loop exceptions?

What is the best practice for handling exceptions thrown from event handlers/listeners in a event loop? For example: class EventLoop { public: void start(); //create a thread which calls run(); ...
1
vote
2answers
137 views

Why does this implementation of Dijkstra's algorithm work in O(n^2)?

Here is the code I use for implementing Dijkstra's algorithm. Consider a graph with n vertices and m edges. Shouldn't it run in O(n^2 m) ? Someone may say that there are n vertices and each edge gets ...
1
vote
1answer
159 views

Why does this algorithm work in O(n m)?

This is from a blog post on Codeforces. I couldn't really understand why the editorialist goes on to claim that this code works in O(n m) This is a graph problem, where we are supposed to find the ...
0
votes
2answers
300 views

Is factory pattern a right pattern for the situation described here?

Is factory pattern a right pattern when we want to consolidate the related objects? Problem - In the Set-top box, I have a user-io, basically the interface to control the settop box - The user-io can ...
-1
votes
0answers
55 views

Setting Default Parameters in C++ [migrated]

I have a little question about how default values are given to function parameters in C++. The problem I faced is probably due to my lack of understanding as to where the parameters are supposed to be ...
-4
votes
0answers
41 views

“= default” about constructor in c++ [on hold]

struct Sale{ Sale () = default;//I got nothing about those cod Sale(std::istream &input); Sale(const std::string &s):book(s) {} //and so on...... } What did the second code mean? Is that ...
-5
votes
0answers
23 views

Why the output of my programme is 495 instead of 496 [migrated]

#include<cstdio> #include<cstdlib> #include<iostream> #include<cmath> using namespace std; class obj { int arr[100],i,nod,sum; public: int init() { ...
12
votes
3answers
389 views

What is the point of making a syntactic distinction between standard and user-defined types?

Although here I will refer specifically to C++ and Bjarne Stroustrup's naming conventions, in principle, I've seen that people use somewhat similar rules for other languages here and there. So, the ...
1
vote
1answer
121 views

C++ Template Metaprogramming and Call By Need Evaluation

I recently wrote a fairly complex C++ meta function that boils down to: template <size_t N, typename val> struct Rec { using type = typename std::conditional<N == 0, val, ...
-1
votes
0answers
34 views

Binary Search scheme alteration [closed]

I'm having a bit of an issue with programming an algorithm..... below would involve some of the details of the assignment; now before you begin to say that I should actually attempt, in solving this ...
-6
votes
0answers
51 views

Can I balance a full-time job and a programming internship? [closed]

Though I didn't get my degree in Comp Sci, I studied in Finance (BA) and Economics (MS) and have picked up programming as a hobby that I'd really like to incorporate in my career. My initial thought ...
-3
votes
1answer
233 views

If-else in C++ Programming Language [closed]

I am a little bit confused about this code. Why does the else block get executed? Please explain it. int a=10,b=20; char x=1,y=0; if(a,b,x,y){ cout << "A" << endl; }else{ cout ...
2
votes
1answer
109 views

Genetic Algorithm's Tournament Selection limit to be selected

I started working again on a Genetic Algorithm and i'm trying a lot of operators and ways of selection. When I made the Tournament Selection , I noticed that it gets really easy to always get the top ...
1
vote
1answer
159 views

Using streams to connect programming languages

I'm trying to run a computation-heavy program that creates an image on a website. Is it possible to compute in C++ and have an output stream that connects to an input stream in Node.js to display an ...
0
votes
1answer
275 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
0answers
52 views

Maximizing reuse out of a function primitive in CUDA

I'm working on the implementation of a few related algorithms in CUDA, all of which require a primitive that we'll call f(). The related algorithms can't simply call f though, as they require f to ...
4
votes
3answers
779 views

Injecting dependencies (DI) in c++ applications

I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class ...
-2
votes
0answers
39 views

package management for C++ project [closed]

I am a programming student looking to apply my programming skills to develop a custom C++ project. My project is an educational software project that includes a main interface that allows the user to ...
23
votes
8answers
10k views

Why was Scala not implemented with C or C++

Does anybody know why was Scala implemented in Java and .NET instead of C or C++? Most languages are implemented with Cor C++ [i.e Erlang, Python, PHP, Ruby, Perl]. What are the advantages for Scala ...
78
votes
14answers
31k views

Why are most browsers developed in C++ [closed]

It seems like most of common web browsers (Firefox, Chrome, Safari) are developed using C++. Whys is that so?
-1
votes
0answers
13 views

C++ , string in a function has always the same length [migrated]

What is wrong with this code? input has always the length of 4 in my function test, no matter if my string is actually longer or shorter. #include <iostream> #include <string> using ...
-2
votes
0answers
48 views

Graphing Logical circuit C++ Programming [closed]

I have written a program in C++ that inputs 3 files that describes a logical (non-sequential if matters) and user in simulation file tells which values to change (Just like ModelSim). I was able to ...
-4
votes
0answers
39 views

Program on cricket scoreboard [closed]

why is the following code not giving results and how to get results? I needed to post whole code because it would be difficult for people to understand the problem without whole code.whenever I run ...
52
votes
11answers
6k views

Did the developers of Java consciously abandon RAII?

As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom: using (var ...
2
votes
1answer
138 views

Insertion sorting Algorithm comparison

I recently came across sorting techniques and of particular, 'insertion sorting'. Although the logic and method is fairly understandable, the actual function seemed a bit complex (given below). ...
6
votes
2answers
9k views

How to run C++ code in browser using asm.js?

An asm.js application is very fast (near native C++ speed): http://kripken.github.io/mloc_emscripten_talk/micro4b.png But how is it possible to write one in C++, convert it to LLVM code, then do ...
-2
votes
0answers
61 views

What are the return values for functions in Google's style guide

I am interested in learning C++ in greater depth by coding algorithms from a theoretical computer science book I am using as a text. As I code the different algorithms, I would like to make my own ...
3
votes
3answers
475 views

Should I try it straight or should I first check if it can be done?

I have a set of items, and each item in the set must be unique. Item are composed from multiple properties and each property of each item can be changed. But after each change every item in the set ...
8
votes
5answers
789 views

How to structure a loop that repeats until success and handles failures

I am a self-taught programmer. I started programming about 1.5 years ago. Now I have started to have programming classes in school. We have had programming classes for 1/2 year and will have another ...
21
votes
4answers
9k views

Where should I put functions that are not related to a class?

I am working on a C++ project where I have a bunch of math functions that I initially wrote to use as part of a class. As I've been writing more code, though, I've realized I need these math functions ...
4
votes
1answer
171 views

Designing interfaces to hardware

I am writing a library in C++ that is used by customers to interface with hardware. There are many different devices that I need to support. For the sake of simplicity, assume I have 2 Widgets, ...
117
votes
19answers
89k views

Is there any reason to use C++ instead of C, Perl, Python, etc.? [closed]

As a Linux (server side) developer, I don't know where and why should I use C++. When I'm going for performance, the first and last choice is C. When "performance" isn't the main issue, programming ...
4
votes
1answer
263 views

What is the status of @ and $ characters in C++?

C++ syntax uses almost all printable ASCII characters and some of them in several contexts. Only two unused are @ and $ characters. Why they are not used? Are they reserved for some "meta" purpose?
3
votes
4answers
364 views

Are `switch` statements generally used wrong? [closed]

I see most developers using switch statements with breaks in each and every case. Is this usage of switch statements inappropriate since a simple set of if-else statements would suffice? Is it OK for ...
0
votes
1answer
402 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 ...
3
votes
5answers
291 views

Storing a pointer to an argument passed by (non-const) reference

When designing an interface for passing objects which are meant to be stored for later use and which should not be 'null', I am always a bit uncertain if the argument should be passed by reference or ...
3
votes
0answers
207 views

How do you pronounce 'char' keyword? [closed]

So, with the possibility of this question being closed due to being non-productive as in the case of other pronunciation questions, I take the risk and ask it just because i have heard it said both ...
-1
votes
0answers
59 views

C++ segmentation fault class with pointer variable [migrated]

[Edited post, based on previous answers and comments. I have tried several strategies, none of which have worked.] I have a class D, with a member variable of class type E. E has two subclasses, E1 ...
29
votes
8answers
3k views

Disadvantages of scoped-based memory management

I really like scope-based memory management (SBMM), or RAII, as it is more commonly (confusingly?) referred to by the C++ community. As far as I know, except for C++ (and C), there's no other ...
1
vote
2answers
198 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 ...
1
vote
2answers
82 views

Class as resource handle & Bad Copy

I am reading Bjarne Stroustrup's book titled "A tour of C++". The following section is confusing to me: When a class is a resource handle – that is, when the class is responsible for an object ...
-1
votes
1answer
58 views

What are some hashmaps we can easily implement? [duplicate]

At many places, I read that we can use HashMap here for O(1) search. Actually, I want to ask how I can implement easy hashmaps which can satisfy this property. Can anyone tell few hashmaps including ...