const-cast
Variable Value Changes By Itself
I\'ve been pretty confused while programming before, but this one takes the cake. Basically I set the value in one for loop, and in the following iteration it changes to the value of the next one.[详细]
2023-04-08 21:20 分类:问答Compiler switch to disable const_cast semantics in c-style casts?
Recently I stumbled over code such as this: void foo(const Bar* b) { ... takes_nonconst_param_fn((Bar*)b);[详细]
2023-02-24 18:00 分类:问答Where is the undefined behavior when using const_cast<>?
If I do: const char* const_str = \"Some string\"; char* str = const_cast<char*>(const_str); // (1)[详细]
2023-02-22 08:55 分类:问答STL std::map, pass by ref to const and the necessity of const_casting
I have a simple question regarding const_cast and best practices regarding STL containers. Consider the following where class Foo has a private STL std::map from Widget* to int:[详细]
2023-01-28 02:43 分类:问答Is const_cast acceptable when defining an array?
I have a static const array class member (const pointers to SDL_Surfaces, but that\'s irrelevant), and have to loop through it in order to populate it. Aside from a const_cast when I\'m done looping,[详细]
2023-01-19 06:19 分类:问答Implications of a const_cast in a copy constructor?
So I\'ve got an output stream class that owns a pointer to a class that actually does the writing, and I need a copy constructor so that I can return initialized instances from a function so that I ca[详细]
2023-01-05 10:35 分类:问答Correct usage(s) of const_cast<>
As a common rule, it is very often considered a bad practice to use const_cast<>() in C++ code as it reveals (most of the time) a flaw in the design.[详细]
2022-12-27 06:12 分类:问答Remove entries from dictionary using LINQ - locking
I have a static dictionary which holds authentications for a web service. I\'m running a timer (hence the TimerCallBack sig on the method below) to remove those authentications which have been dormant[详细]
2022-12-21 22:42 分类:问答Need clarifications in C-style, reinterpret, and const casts
Am I right in assuming that C-style casts (which are discouraged) are nothing but reinterpret_casts? Using the latter is visually striking and easy to search when looking for nasty casts, and hence it[详细]
2022-12-21 21:57 分类:问答Can I get the ExecutablePath from a System.Management.EventArrivedEventArgs object?
I\'m using a System.Management.ManagementEventWatcher to get the process ID and executable path for a started process:[详细]
2022-12-18 12:48 分类:问答