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

learn more… | top users | synonyms

-4
votes
0answers
15 views

Member function to compare calling object with parameter? [on hold]

I'm writing a class with temperature and I'm not sure how to write a member function that requires you to compare the calling object and the parameter. (Like if calling is lower than parameter output ...
1
vote
0answers
42 views

Visual interpolations: independent or linked to object?

I have a class that I use to render GUI elements on the screen, this class has a tree structure (with children, parent, and siblings). I created an additional class which allows me to interpolate some ...
4
votes
1answer
106 views

Which C++ IO interfaces for a complex data source i.e. converter

My question: When you've got a complex converter like, that takes chunks or large result sets out of a database, converts it into a line by line file/resource in the end, should one either design it ...
-4
votes
1answer
69 views

C++ substitution cryptography [on hold]

Is there a way to encrypt a text message by simple substitution? Ex: input +5 Hello World Output Mjqqt Btwqi Where +5 is the char incrementation for the substitution. I'm stuck splitting the ...
24
votes
7answers
2k views

Should a C++ program catch all exceptions and prevent exceptions from bubbling up past main()?

I was once advised that a C++ program should ultimately catch all exceptions. The reasoning given at the time was essentially that programs which allow exceptions to bubble up outside of main() enter ...
12
votes
2answers
2k views

Is using Exceptions at the highest level of a program considered bad practice? [duplicate]

I have seen programs using this strategy and I have also seen posts considering this bad practice. However, the posts considering this bad practice have been written in c# or some other programming ...
-3
votes
0answers
37 views

Is it possible to access protected members of an object from the function of an object whose type is derived from type of first object?

I am aware that access-specifiers are class-based but I want to know if it extends to Inheritance also? Class base { protected: int x; } Class derived: public base { public: void f(base* pb){ ...
0
votes
1answer
75 views

How does the base class non-virtual function get called when derived class object is assigned to base class?

#include <iostream> class Base { private: int b_value; public: void my_func() {std::cout << "This is Base's non-virutal my_func()" << std::endl; } virtual void ...
1
vote
1answer
30 views

Managing Opengl projects under Team Foundation Server

I am learning OpenGL/C++ by following a tutorial series on in2gpu. I set up my Project just like the autor did. It is an Empty Visual C++ Project. Inside the project I linked glew and freeglut, the ...
-3
votes
0answers
108 views

Cons and Pros of ternary operator instead of if/else [closed]

I have some set of code in which same code is written by using two logics. which are as follows. 1. if (cart.getFacebookShare()) { return BigDecimal.TEN; }else{ return BigDecimal.ZERO; } ...
96
votes
13answers
14k views

Should we avoid language features that C++ has but Java doesn't to increase maintainability? [closed]

Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator ...
3
votes
1answer
126 views

C++ class design with invariant

I've been pondering a really basic question about how far to take enforcing a class's invariant. Maybe that's worded badly, so as an example, let's say that I want to write a class which stores a ...
-6
votes
1answer
77 views

Dangerous Dave game parameters live access [closed]

I have searched online for Dangerous Dave source code however I wasn't able to find any. So I wanted to know, is there any way I can access the score and other game parameters while playing the game. ...
3
votes
1answer
600 views

Template Function: Passing Iterators

I am struggling with making a design choice in the following setup: I am writing (C++) functions which take a pair of iterators (to template containers) and compute a return value of the same type ...
20
votes
8answers
2k views

How did you become a const correctness convert? [closed]

After 15 years of C++, I've still haven't learn to love using const. I understand it's use, but I've never actually been in situation where being const correct would have avoided the problem I was ...
1
vote
2answers
173 views

Preferable design of scope guard in C++

Recently, I come across an issue about the design of scope guard. A scope guard invokes a supplied function object (usually performs cleanup procedures) upon exiting the enclosing scope. The current ...
97
votes
11answers
31k views

What backs up the claim that C++ can be faster than a JVM or CLR with JIT? [closed]

A reoccurring theme on SE I've noticed in many questions is the ongoing argument that C++ is faster and/or more efficient than higher level languages like Java. The counter-argument is that modern JVM ...
43
votes
5answers
8k views

Why are reference-counting smart pointers so popular?

As I can see, smart pointers are used extensively in many real-world C++ projects. Though some kind of smart pointers are obviously beneficial to support RAII and ownership transfers, there is also a ...
1
vote
4answers
855 views

Common header file for C++ and JavaScipt

I have an app that runs a C++ server backend and Javascript on the client. I would like to define certain strings once only, for both pieces of code. For example, I might have a CSS class ...
31
votes
9answers
6k views

Is the algorithm more important than the programming language?

During the current (2013) Google Code Jam contest, there was a problem that took C++ and Java people 200+ lines of code as compared to Python people that solved the same problem only using 40 lines of ...
-1
votes
1answer
63 views

2D Animating in OpenGL [closed]

I am trying to animate a texture in OpenGL. I feel like it should be easy, as I know how to animate in SDL and other libraries but I am having trouble. I have a x,y,w,h that holds the texture ...
12
votes
2answers
4k views

How does C++ handle multiple inheritance with a shared common ancestor?

I'm not a C++ guy, but I'm forced to think about this. Why is multiple inheritance possible in C++, but not in C#? (I know of the diamond problem, but that's not what I'm asking here). How does C++ ...
24
votes
9answers
4k 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 ...
1
vote
1answer
93 views

Does it make sense to have a user specified thread limit?

I'm developing a C++14 application and would like to take advantage of the new multithreading features, in particular std::async. I have seen a number of applications which allow the user to specify ...
2
votes
3answers
153 views

Why does the overriding rule of C++ not care about visibility changes?

In C++, it is possible to write an overriding for a base class's method even if the visibility declaration of the two don't match. What are the possible design considerations under the decision of not ...
-1
votes
0answers
69 views

Can we create variable length arrays in c++ [migrated]

I am trying to create this simple program which displays the data of the array back to the user again.. I want to create a variable length array. In this program the user is first asked the number of ...
2
votes
2answers
1k 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 ...
4
votes
4answers
356 views

Why does integer division result in an integer?

We learned in Intro to Programming that if you divide two integers, you always get an integer. To fix the problem, make at least one of those integers a float. Why doesn't the compiler understand I ...
1
vote
0answers
79 views

Pure abstract classes for input-, output- and bidirectional-pin of microcontroller

I'm writing a real-time operating system for microcontrollers in C++11 - distortos. Currently I'm thinking about a C++ framework for various peripherals. The most basic peripheral which I would like ...
3
votes
2answers
254 views

Is it possible to have pointers recursively point into themselves?

I have been learning C++ recently, and upon reading up on pointers I had a moment of thought. I'm still attempting to grasp the very idea of pointers so excuse me if this doesn't make sense beyond ...
0
votes
2answers
102 views

node.js C++ addons to do all major computations [closed]

A major limitation of node.js is its single threaded execution and the fact that JS is slow with computations. What are the advantages/drawbacks of using C++ to do the application's heavy lifting ...
2
votes
0answers
192 views

Is it a good practice to use virtual inheritance as default? [closed]

Why virtual inheritance is not used as default? Default as in by the programmer and not the language. If not, why? What are the cases where it may fail? Is there some run time overhead? Is it ...
1
vote
0answers
41 views

Is it possible to maintain one code base and deploy on both spir/open-cl and ptx/cuda?

It is my understanding that both spir and ptx are based on llvm. Binaries can be generated by clang for use along with the native graphics compute drivers (e.g. open-cl and cuda). My question is ...
-3
votes
0answers
13 views

call by reference in functions [migrated]

I am practicing functions in C++. In some random notes, I found an example of functions call by value and call by reference. The code is #include <string.h> #include <iostream> ...
14
votes
7answers
35k views

Why are constructors not inherited?

I am confused as to what the problems could be if a constructor was inherited from a base class. Cpp Primer Plus says, Constructors are different from other class methods in that they create ...
2
votes
2answers
641 views

Any OOP design pattern that is somewhat representative of all of the SOLID OOP design principles at play?

I'm trying to teach an object oriented design principles course (on SOLID) at a training institute. I also want to teach the students a few OOP design patterns such as factory, singleton and one ...
1
vote
2answers
139 views

Parameterization vs subclassing

Example taken from : Agile software development : principles, patterns and practices A new employee is added by the receipt of an AddEmp transaction. This transaction contains the employee's name, ...
1
vote
1answer
59 views

Modeling specific objects interaction

I want to model an interaction between classes, e.g. there is a general class Hero and he can have some items. (I came up with this analogy so it is easier to understand) Some of them are e.g. potions ...
4
votes
3answers
228 views

I want to overload a function with the same type parameter; what should I do?

I'm creating an API, and I want to overload a function for strip: QString MyClass::strip(); QString MyClass::strip(QRegularExpression open); QString MyClass::strip(QRegularExpression close); QString ...
11
votes
8answers
482 views

How does a variable introduce state?

I was reading the "C++ Coding Standards" and this line was there: Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible. ...
3
votes
2answers
291 views

Is it good practice to have your C++/Qt functions always check all its arguments for null values?

Backstory While developing with Qt Signal/Slots, I came across a few segmentation faults that had me puzzled as to what was causing it. Eventually I figured out that you could actually pass a slot ...
22
votes
1answer
2k views

Why does the documentation on some languages say “equivalent to” rather than “is”?

Why does the documentation on some languages say "equivalent to" rather than "is"? For example, the Python Docs say itertools.chain(*iterables) ... Equivalent to: def ...
6
votes
5answers
325 views

What does it mean to declare a volatile variable?

Many low level programs use the volatile keyword for types for memory mapping and such, however I'm sort of confused as to what it REALLY does in the background. In other words, what does it mean ...
5
votes
4answers
424 views

Trying to get a better understanding of object-oriented design's performance pitfalls

I'm currently in a high-performance computing class taught in C++. Usually, I do work in C#, meaning everything is taken care of for me, and optimization comes behind maintainability and higher-level ...
8
votes
3answers
287 views

Anonymous namespaces make code untestable

Here is a typical C++ code: foo.hpp #pragma once class Foo { public: void f(); void g(); ... }; foo.cpp #include "foo.hpp" namespace { const int kUpperX = 111; const int ...
3
votes
6answers
170 views

OpenGL, multithreading, and throwing destructors

How do you make an class that properly warns a developer in the future that they've made a mistake somewhere in their implementation that resulted in an object that gets deconstructed in a state that ...
2
votes
3answers
2k views

Design choices when doing multithreading in C++

OK, so, background: I have a little "server" app/module that is written in C++. This is kindof a tunnel application that provides a standardized API via TCP/IP[a] and on the other hand talks to the ...
34
votes
8answers
7k views

Explanation on how “Tell, Don't Ask” is considered good OO

This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def ...
2
votes
3answers
178 views

C++ Virtual destructors used only when there are virtual functions

This is from Effective C++ (Meyers): Classes not designed to be base classes or not designed to be used polymorphically should not declare virtual destructors I don't understand why ...
30
votes
9answers
2k views

Is possible to write too many asserts?

I am a big fan of writing assert checks in C++ code as a way to catch cases during development that cannot possibly happen but do happen because of logic bugs in my program. This is a good practice in ...