Question: Say, I want to create a File class

```
class File{
    public:
          File(const char *file){
               openFile(file);
          }
          ~File();
          isEmpty();
};

```

openFile checks if the file exists or if the contents of the file are valid or not.

```
File *file = new File("filepath");
if(file)
file->isEmpty();

```

if my filepath is correct, then all fine, file instance is proper and we can invoke `file->isEmpty();`
What is the file does not exist, in that case still the check `if(file)` evaluates to true and will lead to creation of file instance which is actually invalid. How can i guarantee that if file path is invalid, the file instance should be null.

Answer: 
Your constructor should throw an exception in the case that the file couldn't be opened.

```
File::File( const char* pPath )
{
  if ( !openFile( pPath ) )
    throw FileNotFound( pPath );
}

```
If I understand what you correctly, you want to return null from the constructor when `"filepath"` is invalid? This isn't (directly) possible in C++, although there are a few possibilities. You could throw an exception from your constructor, but this can get hairy in C++. You could have some functions that can check the validity of a File object, so `if(file)` would become `if(isValid(file))`. You could also wrap some of this logic in some sort of factory that would return null if the file to be created is invalid.