大约有 118 项符合查询结果(耗时:0.0224秒) [XML]
Do I cast the result of malloc?
...style cast is also bad (unless you're using a very old C++ compiler). And static_cast>() (or reinterpret_cast<>() )is not compatible with any dialect of C.
– David C.
Feb 12 '16 at 23:12
...
What are all the common undefined behaviours that a C++ programmer should know about? [closed]
...value that can't be represented by the target type (either directly or via static_cast)
Using an automatic variable before it has been definitely assigned (e.g., int i; i++; cout << i;)
Using the value of any object of type other than volatile or sig_atomic_t at the receipt of a signal
Attempt...
Is 'float a = 3.0;' a correct statement?
...better documents your intention. Using an explicit conversions for example static_cast also helps to clarify the conversion was intended as opposed to accidental, which may signify a bug or potential bug.
Note
As supercat points out, multiplication by e.g. 0.1 and 0.1f is not equivalent. I am just...
How to implement an STL-style iterator and avoid common pitfalls?
...e(data, size))
{
std::cout << " char: " << static_cast<char>(n) << std::endl;
}
}
{
// Only for iterator test
ptr_iterator<uint8_t> first(data);
ptr_iterator<uint8_t> last(first + size);
std::vect...
What's the difference between std::move and std::forward
...h cover 99.9% of the usefulness of rvalue reference casts), you should use static_cast directly and write a good explanation of what you're doing.
share
|
improve this answer
|
...
Difference between private, public, and protected inheritance
...r class: Implicit conversions from the derived to the base won't work, and static_cast from the base to the derived won't work either.
Only members/friends of a class can see private inheritance, and only members/friends and derived classes can see protected inheritance.
public inheritance
IS-...
When is a C++ destructor called?
...emory large enough to hold 5 Foo objects.
int n = 5;
char *chunk = static_cast<char*>(::operator new(sizeof(Foo) * n));
// Use placement new to construct Foo instances at the right places in the chunk.
for(int i=0; i<n; ++i)
{
new (chunk + i*sizeof(Foo)) Foo(i);...
When do I use fabs and when is it sufficient to use std::abs?
...using mpreal there are cases with hard "ambiguous overload" messages - abs(static_cast<T>(x)) isn't always solving that.
When abs is ambiguous, there are chances that fabs is working as expected. For sqrt I found no such simple escape.
Since weeks I'm hard struggling on C++ "not existing prob...
C++ valarray vs. vector
...ctor example. (By the way, if mean is really int, not double, you may need static_cast<double>(mean).)
– musiphil
Mar 27 '13 at 23:12
...
Why do std::shared_ptr work
...:
template <typename T>
void delete_deleter( void * p ) {
delete static_cast<T*>(p);
}
template <typename T>
class my_unique_ptr {
std::function< void (void*) > deleter;
T * p;
template <typename U>
my_unique_ptr( U * p, std::function< void(void*) > d...