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

learn more… | top users | synonyms

-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() { ...
-1
votes
0answers
31 views

Binary Search scheme alteration [on hold]

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
39 views

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

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
218 views

If-else in C++ Programming Language [on hold]

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 ...
1
vote
1answer
135 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 ...
1
vote
0answers
36 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 ...
2
votes
1answer
91 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 ...
-2
votes
0answers
36 views

package management for C++ project [on hold]

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

Graphing Logical circuit C++ Programming [on hold]

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
37 views

Program on cricket scoreboard [on hold]

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 ...
2
votes
1answer
135 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). ...
-3
votes
0answers
41 views

arithmetic operations + connect to DB .. how to code [closed]

Constant A , B Variable AX, YB , ZB , Bx, capB Input Y1 Input Z1 Function { AX=AX+YB If ZB < CapB then Bx=Bx-ZB Not return error } I am using Xcode ...
-2
votes
0answers
60 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 ...
-4
votes
0answers
22 views

How to make option menu enebled and working? [closed]

I added event handler to Import menu option and implemented action in code void CImportDial::OnFileImport32772() { CImportDial importDlg; importDlg.DoModal(); } void ...
-3
votes
0answers
73 views

learning C++,PHP and Java at the same time? [closed]

I LOVE programming, i want it to be my career and my life, that's how much i love it, but here is the problem, our school system in my country only taught VB6 and QB (yes QUICK freaking BASIC), so i ...
1
vote
1answer
118 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, ...
-2
votes
0answers
65 views

Text Editor with Autocomplete in C/C++ and OpenGL [closed]

I am looking for a text editor that is capable of auto complete for c/c++ for OpenGL coding. I will be writing a game and want to go with a text editor instead of a full-fledged IDE so that I can ...
3
votes
3answers
472 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 ...
4
votes
1answer
258 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
349 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 ...
3
votes
0answers
202 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 ...
1
vote
2answers
80 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
57 views

What are some hashmaps we can easily implement?

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 ...
1
vote
1answer
99 views

Constructor vs casting operator

I'm programming a library (so I have complete access to all the mentioned classes). Two classes (A and B) are essentially the same and differ only by their implementation, so they can be easily ...
4
votes
1answer
165 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, ...
9
votes
6answers
772 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 ...
9
votes
7answers
911 views

Will a profound knowledge of C++ help you in learning other languages faster/easier? [closed]

Is there a possibility that someone who has learned all the key aspects of C++ and knows the fundamentals of the language very well, will learn other languages (such as, Python, Perl, Java) faster and ...
-2
votes
2answers
337 views

What is the simplest and universal algorithm for parsing C++ code? [closed]

I need to do some project specific automatic checking of source codes written in C++ Limitations: Algorithm and its implementation should be simple, easily maintainable, extendable and ...
3
votes
2answers
187 views

Is it always safe to shift bool values?

I stumbled about a Cppcheck warning (an inconclusive one), that I mistakenly used & instead of &&: /// @param code identifies the command. Only the lower 16 bits of are being processed ...
0
votes
3answers
53 views

Defining resource allocation in method documentation

I want to write a library with "no resource leak guarantee" feature. So I shall know whether each method allocates any resource or not. It may change the code. For example: void foo() { ...
4
votes
2answers
209 views

Needs (in principle) C++ parenthesis around if statement condition?

In current C++ when body of if statements contain only one command then: Parenthesis around if condition are mandatory but block are optional. So, both examples are OK: if ( condition ) { return 0; ...
2
votes
2answers
142 views

Use of raw pointer of std::vector

I am currently maintaining a code that makes liberal use of raw pointers where std::vector would be a better option. Worse, these pointers are not always properly handled (when run using Intel ...
3
votes
2answers
167 views

How to deal with historic exception specifications in maintained C++ code

Today, I discovered a few exception specifications in legacy code I've to maintain, when Cppcheck 1.68 ([Inconclusive] but correctly) pointed out that the specified exceptions are not handled in ...
0
votes
0answers
6 views

count even length words in vectors [migrated]

I have 2 problems. 1) cout << v_setir.capacity(); is not returns the correct number. 2) I want to count of the words which lengths are even. and I should do it with vectors. Here is my codes: ...
0
votes
0answers
97 views

Requesting information regarding the use of MUI vs. the use of GetText for i18n/L10n of Windows desktop applications

I have spent the past two days investigating which technology I will use to support translations of text strings (as part of an overall internationalization migration) for an archaic (VC6) Windows ...
1
vote
1answer
136 views

Where should I place a typedef when used in method signatures in C++?

I'm using an Optional class quite similar to that of boost. For semantic reasons, I switched an attribute of the same (structured) type in some class definitions (and therefore also in method ...
-3
votes
0answers
12 views

Recursive solution for 3n+1 [migrated]

I just like to do simple recursion. For a number if it is even then it'll approach to (number/2) and if odd then to (3*number+1). How many time it'll occur to reach 1. for 10 10-> 5-> 16-> 8-> 4 ...
2
votes
3answers
3k views

Efficient algorithm to count number of substrings divisible by 3

Given a string of decimal digits, I have to find the number of all substrings divisible by 3 in the range L to R [both inclusive], where L & R are index[1-based] of the specified string string ...
0
votes
1answer
75 views

Is it possible to save and load a decorated object

I am wondering if there is an easy way to save and load a decorated object in c++ as i have never done file handling in C++ before. Currently the only object type I need to save is objects that ...
2
votes
1answer
75 views

How to make max-heap stable with counter and account for counter overflow?

Generally I need size-efficient data structure similar to std::priority_queue but stable (preserving order of insertion). By adding just 4 bytes to the object I could have 1 byte serving as priority ...
1
vote
2answers
145 views

Unsure about the decorator design pattern

I'm fairly new at using design patterns and I am currently making a small game for my uni course that I have to use the decorator pattern for creating the different classes of NPC however I think that ...
0
votes
0answers
9 views

C++ 3D Matrix Using References [migrated]

Request for a sanity check ... I am storing a 3D matrix in a 1D array as follows: double * myVector = new double[NCHANNELS*NROWS*NCOLUMNS]; I want to be able to access myVector using ...
24
votes
9answers
3k views

What is different between the internal design of Java and C++ that lets C++ have multiple inheritance? [duplicate]

It's drilled into the newbie Java programmers that Java (pre-Java 8) has no multiple class inheritance, and only multiple interface inheritance, because otherwise you run into diamond inheritance ...
0
votes
0answers
42 views

Mailbox Pattern with Variable Arguments in C++

In a game I'm developing, the GUI thread is catching user actions, and the simulation thread is responsible of handling and responding to them. To minimize complexity and delay, I predefined all ...
-1
votes
0answers
69 views

How do I call a parameterless function pointer from within a class? [migrated]

This is an extended new question from my last post: How do I use function pointers within this class? I have three members in my class: void (X2D::Graphics::OpenGL::Circle::*draw_ptr)(void); void ...
-1
votes
0answers
52 views

How do I use function pointers within this class? [migrated]

I have a class: Circle. It can draw either a filled circle or an outlined circle. Based on its current setting, I want a general draw() method that calls either draw_filled() or draw_outlined(). In ...
-2
votes
0answers
24 views

TextOut() - “invalid null pointer” [migrated]

I've written a program in C++ which is displaying a white window. Furthermore I'm displaying a text in the window. To accomplish this purpose, I use the TextOut()-Function. It's working, but besides ...
1
vote
2answers
83 views

How do you decide member objects?

So OOP is about breaking down functionality, making each class responsible for one thing etc. But let's take the example where an object is using another object. First thing that comes to mind ...