I am trying to extend std::map's std::pair entries with some extra functionality and want to cast such pairs to a child class of pair. Note that this ...
I am trying to extend std::map's std::pair entries with some extra functionality and want to cast such pairs to a child class of pair. Note that this ...
This question is motivated by the following (simplified) example. Compiling with all warnings enabled, the compiler issues a This is clearly not ...
I'm reviewing a lot of code where I need to ensure there are no static_cast (or any cast) calls on variables that could be out of range of the enum cl ...
I found one more case when compiler thinks that static_cast may return nullptr on non-nullptr argument. It seems that this time there is no undefined ...
I am new to C++ and have the following simple code snippet exploring C++ limitations: Why is the output showing me different values for x & y e ...
In an "Entity" class, there is a function that takes in a component typename as an argument, and should return a pointer to that component, if found i ...
I have user-defined type: The problem is when I'm trying to perform some explicit casts, the wrong operator is called: I want operator char() co ...
This can be compiled (despite being UB (right?) because fvp == nullptr) int f; void* fvp{}; decltype(f)* fp = static_cast<decltype(f)*>(fvp); ...
We ran into this scenario in our codebase at my work, and we had a big debate over whether this is valid C++ or not. Here is the simplest code example ...
Conversion from SI to ImperialSystem is working but the reverse isnot working. The error message: static_cast: cannot convert from ImperialSystem to S ...
I discover this compiler trick and I cannot find a name for. Have you any idea? On an Intel processor, I can cast a variable from its base class to an ...
Given an enum class stored in a bit-field: #include <cstdint> #include <iostream> enum class Orientation: uint8_t { NORMAL = ...
When I write a class like this static_cast() calls the custom conversion operator. But static_pointer_cast() does not compile. Why is that, and what d ...
Considering the following function template func declared within MyClass class template: Is there any advantage in calling static_cast< oT >( ...
I try to follow the mantra of "no warnings." I try to write my code so that the compiler gives no warnings. I'm starting to use non-standard libraries ...
I need to allocate a chunk of memory using malloc and then store multiple values of different plain old data types in there. Is the following a correc ...
I read somewhere that a pointer-to-member of a derived class can be converted to pointer-to-member of its base class. When I have read this, my smart ...
I got the error: I'm following a simple C++ tutorial as I am a beginner. ...
I think that I am misreading the standard quotation, hence I do not fully understand what's the exact intent of the wording. Firstly, I am already aw ...
I am wondering about a short code example of an application of downcast via static_cast, under conditions where there is no undefined behaviour. I hav ...