class C
{
private:
FILE* p;
public:
C() { p = new FILE(.....); }
operatorbool () const { return (p != NULL) ; }
};
And I wanna do something like this:
1 2 3 4 5 6 7
C* c;
c = new C;
if (c)
cout << "file loaded";
else
cout << "file not loaded";
Of course this code doesn't work as expected because c is a pointer to C and "if(c)" only checks if c is valid.
So, How can invoke the conversion-to-bool in this case?