大约有 4,041 项符合查询结果(耗时:0.0261秒) [XML]
Should I use an exception specifier in C++?
In C++, you can specify that a function may or may not throw an exception by using an exception specifier. For example:
14 ...
How many and which are the uses of “const” in C++?
As a novice C++ programmer there are some constructs that look still very obscure to me, one of these is const . You can use it in so many places and with so many different effects that is nearly impossible for a beginner to come out alive. Will some C++ guru explain once forever the various uses a...
Is there a standard sign function (signum, sgn) in C/C++?
...
Surprised no one has posted the type-safe C++ version yet:
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}
Benefits:
Actually implements signum (-1, 0, or 1). Implementations here using copysign only return -1 or 1, w...
Declaring pointers; asterisk on the left or right of the space between the type and name? [duplicate
I've seen mixed versions of this in a lot of code. (This applies to C and C++, by the way.) People seem to declare pointers in one of two ways, and I have no idea which one is correct, of if it even matters.
...
throwing exceptions out of a destructor
...he noexcept(false) so the code keeps its original meaning.
// Post C++11 destructors are by default `noexcept(true)` and
// this will (by default) call terminate if an exception is
// escapes the destructor.
//
// But this example is designed to show that term...
function declaration isn't a prototype
...arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.
If you have a variable a, extern int a; is a way to tell the compiler that a is a symbol that might be present in a different...
Why is there no std::stou?
C++11 added some new string conversion functions:
3 Answers
3
...
What is a smart pointer and when should I use one?
...at the time, which was smart pointers provided by the Boost library. Since C++11, the standard library has provided sufficient smart pointers types, and so you should favour the use of std::unique_ptr, std::shared_ptr and std::weak_ptr.
There was also std::auto_ptr. It was very much like a scoped ...
Is there a performance difference between i++ and ++i in C++?
...ive Summary: Use ++i if you don't have a specific reason to use i++.]
For C++, the answer is a bit more complicated.
If i is a simple type (not an instance of a C++ class), then the answer given for C ("No there is no performance difference") holds, since the compiler is generating the code.
Howe...
Iterator Loop vs index loop [duplicate]
I'm reviewing my knowledge on C++ and I've stumbled upon iterators. One thing I want to know is what makes them so special and I want to know why this:
...