RAII and smart pointers in C++
In practice with C++, what is RAII, what are smart pointers, how are these implemented in a program and what are the benefits of using RAII with smart pointers? 6 Answers 6
In practice with C++, what is RAII, what are smart pointers, how are these implemented in a program and what are the benefits of using RAII with smart pointers? 6 Answers 6
Why is it wrong to use std::auto_ptr<> with standard containers? 6 Answers 6
Do I need to manually call close() when I use a std::ifstream? For example, in the code: std::string readContentsOfFile(std::string fileName) { std::ifstream file(fileName.c_str()); if (file.good()) { std::stringstream buffer; buffer << file.rdbuf(); file.close(); return buffer.str(); } throw std::runtime_exception(“file not found”); } Do I need to call file.close() manually? Shouldn’t ifstream make use of RAII for closing … Read more
Most people say never throw an exception out of a destructor – doing so results in undefined behavior. Stroustrup makes the point that “the vector destructor explicitly invokes the destructor for every element. This implies that if an element destructor throws, the vector destruction fails… There is really no good way to protect against exceptions … Read more
Does C++ support ‘finally‘ blocks? What is the RAII idiom? What is the difference between C++’s RAII idiom and C#’s ‘using’ statement? 16 Answers 16
What is meant by Resource Acquisition is Initialization (RAII)? 10 Answers 10