Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 123788

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

1 vote

Short circuit evaluation is C++?

The text you quoted would convince me never to let anyone buy this book. && and || are not bitwise operators, they are logical operators. & and | are bitwise operators, and they are not short-circui …
gnasher729's user avatar
  • 47.5k
0 votes

How to make the choice between non-copyable non-movable types and move-only types without re...

Having a move constructor is just a (very useful) optimisation for situations where the language used to force you to have two objects for a short time, when you really only wanted one. For example, …
gnasher729's user avatar
  • 47.5k
9 votes

Why can't I check whether a mutex is locked?

It seems that you are using the secondary mutexes not to lock access to an optimisation problem, but to determine whether an optimisation problem is being optimised right now or not. That is complet …
gnasher729's user avatar
  • 47.5k
1 vote

Using different C++ compilers and language versions when developing a single executable

One big problem when changing compilers is undefined behaviour: If the code that you receive invokes undefined behaviour, then anything is possible - including that the code works just fine and passes …
gnasher729's user avatar
  • 47.5k
1 vote

Is it a bad practice to include stdlib header file from a header file corresponding to the s...

The rule is: Every header file should be capable of being compiled on its own. If you have a file myheader.h, then a source file with a single line #include "myheader.h" should compile. If your head …
gnasher729's user avatar
  • 47.5k
3 votes

Unique physical objects (Hardware drivers) in C++

You assume that you will have one radio. Obviously you might have zero radios, and there is no reason to believe that there could never be multiple radios. To be future proof: Have a class that retu …
gnasher729's user avatar
  • 47.5k
0 votes

Is it bad code design to use an out of scope static variable?

If you think you want to be able to modify counter, then you create a function setCounter(value). Not caring at the moment how you do it. Having a function returning the address of the variable is an …
gnasher729's user avatar
  • 47.5k
1 vote

What's the reason for not using C++17's [[nodiscard]] almost everywhere in new code?

As an example: operator<< has a return value that is depending on the call either absolutely needed or absolutely useless. (std::cout << x << y, the first is needed because it returns the stream, the …
gnasher729's user avatar
  • 47.5k
-3 votes

Use case comparison for std::optional vs default argument

“optional” should be used for things that are genuinely not there, and not for default values. So if it is possible that there are no print settings, make it optional. If you decided to use default va …
gnasher729's user avatar
  • 47.5k
1 vote

C++ and memory safety

Before you go in deep, look at what “memory safe” in other languages means. A[i] = 0 with out of range i can overwrite a random memory location. Or it can instantly crash your software. Or it can thro …
gnasher729's user avatar
  • 47.5k
1 vote

True cost of virtual dispatch in C++ - when stop using it?

You should stop using virtual calls if: This leads to a measurable speed improvement. For in-house software: Cost savings due to the speed improvement demonstrably outweigh the development cost. Fo …
gnasher729's user avatar
  • 47.5k
1 vote

Prefer passing class or variable as const reference

How would you describe the function? “It takes an A object and extracts all the bits that it needs”, or “it takes an info object and extracts all the bits it needs”? What does the caller expect? That’ …
gnasher729's user avatar
  • 47.5k
0 votes

changing value of a private member of a class in c++ without using member or friend function

There are very few guarantees about the layout of instance variables in C++. For example, the presence of the "private" or "public" keyword means that the C guarantee about members have ascending memo …
gnasher729's user avatar
  • 47.5k
0 votes

Whether to use -pedantic flag in g++ or not?

Use all warnings that are useful or mostly useful. Try all the options. Turn one on, and look at the warnings. Then you decide: Do these warnings show situations where a bug might be hiding? Or do the …
gnasher729's user avatar
  • 47.5k
0 votes
Accepted

Help with optimizing virtual method

I bet it doesn’t make a difference. If it does: Implement your function with a non virtual inline function named inline_f which has a T* pthis as the first argument and put it in the header file. Then …
gnasher729's user avatar
  • 47.5k

1
2 3 4 5
11
15 30 50 per page