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

learn more… | top users | synonyms

-4
votes
0answers
14 views

i cant send data with SIM800L at server [on hold]

I try to send data to a server using the SIM800L and microcontroller 328p. I'm doing the program with atmel studio Someone will have a code example? Tanks!!
0
votes
1answer
111 views

Function pointers vs. Derived classes

So I have a Signal class and a client class which manages a list of Signal objects. The class provides a bunch of interfaces, one of them is an update()-function. The update()-code is completely ...
4
votes
1answer
117 views

Importing namespaces inside another namespace

I generally like to organize classes I make into modules by using namespaces, and I also don't go more than 2 namespaces deep but it's still painstakingly hard to fully qualify everything. I've ...
-4
votes
0answers
26 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
49 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
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 ...
4
votes
1answer
108 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 ...
-3
votes
0answers
38 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
79 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
32 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
1answer
130 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 ...
11
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 ...
25
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 ...
1
vote
2answers
176 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 ...
-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 ...
96
votes
13answers
15k 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 ...
2
votes
1answer
95 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 ...
-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
3answers
154 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 ...
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 ...
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 ...
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 ...
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> ...
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
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 ...
23
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 ...
1
vote
2answers
140 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, ...
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 ...
8
votes
3answers
289 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 ...
2
votes
3answers
180 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 ...
3
votes
2answers
293 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 ...
7
votes
5answers
329 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 ...
9
votes
2answers
438 views

Interface Segregation Principle: What to do if interfaces have significant overlap?

From Agile Software Development, Principles, Patterns, and Practices: Pearson New International Edition: Sometimes, the methods invoked by different groups of clients will overlap. If the overlap ...
-1
votes
2answers
90 views

Translate MATLAB expressions containing “^” power operator to C++ syntax [closed]

Brief: I have several very large math expressions written in Matlab/Octave syntax. I want to evaluate them within a C++ function by copy and pasting them in, however the problem is they contain "^" ...
0
votes
2answers
161 views

Is declarative programming overrated? [closed]

I've been programming for years with primarily-imperative languages (C++, C#, javascript, python), but have recently experimented with some functional langauges (Lisp, Haskell) and was excited to try ...
2
votes
1answer
80 views

How are objects stored in unordered_sets?

I've been doing a bit of research on the subject. I know unordered_sets are hash tables, where the key and value are one and the same. What I'd like to know is how the compiler figures out where in ...
0
votes
1answer
62 views

Containers and shared ownership within a class instance

I have two objects as member variables of a class. std::unique_ptr<Object> specificObject; std::vector<std::unique_ptr<Object>> objects; I know that specificObject will always be ...
3
votes
6answers
171 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 ...
5
votes
4answers
288 views

Is it true that calling _exit() instead of exit() won't prevent static destructors from being called?

On comp.lang.c++.moderated@googlegroups.com, Greg Herlihy posted the following extern "C" function: extern "C" { int func() { wchar_t memoryName[256]; wchar_t mutexName[256]; ...
7
votes
4answers
2k views

Should I be using advanced techniques most of the time at my new job just because I can? [closed]

Simply put I'm new to the company, should I rather write advanced techniques with things like templates, std techniques..etc to make a first good impression and have my colleagues trust/be impressed ...
5
votes
4answers
412 views

Does making a method static save memory on a class you'll have many instances of?

In response to Aaronaught's response to the question at: Can't I just use all static methods? Isn't less memory used for a static method? I am under the impression that each object instance carries ...
2
votes
2answers
99 views

Managing widgets in a simple GUI framework

So, I'm still working on my small GUI "library". (C++ with boost) The goal is to provide a simple solution for small SPI displays, using a Raspberry or some embedded board. Thus, I ended up having a ...
3
votes
2answers
102 views

How can I create extensible reader and writer wrappers around a shared opaque resource class?

In C++, Say I have a Buffer class (cannot be inherited) which is given and can support the following operation: class Buffer { public: void write_buffer(Data); Data read_next_data(); }; Now ...
13
votes
3answers
426 views

How wrong is it to talk about C++ “methods” (versus “member functions”)?

I understand that according to the C++ spec there is no such thing as a "method", and some (many? most?) C++ programmers consider "method" to be a Java-ism. On the other hand, even on a C++ forum ...
33
votes
9answers
2k views

Doesn't “always initialize variables” lead to important bugs being hidden?

The C++ Core Guidelines have the rule ES.20: Always initialize an object. Avoid used-before-set errors and their associated undefined behavior. Avoid problems with comprehension of complex ...
7
votes
2answers
937 views

Should one derive / inherit from std::exception?

While designing my first 'serious' C++ library, I'm asking myself: Is it good style to derive ones exceptions from std::exception and it's offsprings?! Even after reading Designing exception ...
20
votes
2answers
2k views

Are header-only libraries more efficient?

Assumptions One of the advantages of header-only libraries for C++ is that they do not need to be compiled separately. In C and C++ inline makes sense only if the function is defined in a header ...
4
votes
3answers
347 views

Avoiding constructors with many arguments

So I have a factory which creates objects of different classes. The possible classes are all derived from an abstract ancestor. The factory has a configuration file (JSON syntax) and decides which ...