TwITe

Untitled

Dec 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. class file {
  7. private:
  8.     fstream data_file;
  9. public:
  10.     file (const char* filename) {
  11.         data_file.open(filename);
  12.         if (!data_file.is_open()) {
  13.             throw("file open failure");
  14.         }
  15.     }
  16.  
  17.     ~file() {
  18.  
  19.         if (!data_file.is_open()) {
  20.             cout << "Destructor was called after throwing an error in the constructor";
  21.         }
  22.         else {
  23.             cout << "Destructor was called";
  24.         }
  25.     }
  26. };
  27.  
  28. int main() {
  29.     file file1("asd");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment