Created
April 14, 2009 10:04
-
-
Save allen501pc/95100 to your computer and use it in GitHub Desktop.
To implement a object as fstream with operator ! and open()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usage: To implement a object as fstream with operator ! and open() | |
* Author: Allen ([email protected]) | |
* Date: 04/14/2009 | |
* Output: | |
* object has been opened! | |
*/ | |
#include <iostream> | |
using namespace std; | |
class object | |
{ | |
private: | |
bool isset; | |
bool notopen; | |
public: | |
object() | |
{ | |
isset=false; | |
notopen=true; /* Set it is not opened! */ | |
} | |
bool operator!(); /* ! operator for checking open or not */ | |
void open() | |
{ | |
notopen=false; /* set it is opened */ | |
} | |
}; | |
/* operator ! for checking that opened or not | |
* if open, return false | |
* Or, return true | |
*/ | |
bool object::operator!() | |
{ | |
return this->notopen; | |
} | |
int main(int argc,char * argv[]) | |
{ | |
object ob; /* take class object as ob */ | |
ob.open(); /* open */ | |
if(!ob) | |
{ | |
cout << "object has not been opened! " << endl; | |
} | |
else | |
cout << "object has been opened! " << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment