Failing from a constructor?

 

class Abc {

public:

Abc(string def) {

if (def != "") {

// parse def

} else {

error... how do we report an error? can I just make the constructor return something? e.g. bool Abc(string def) ?

}

}

}

 
Constructors do no return anything. They can not fail; they must not fail. Rewrite your code. Move the parts that can fail into an initializer.
 

Please EDIT your post and use the "</>" (Alt-S) for your code sample. Don't use simple text. It makes it difficult to read.

Constructors don't have return values. You can just set an internal state (member variable) to signify if it is valid or not. An option is to set a user error ...

SetUserError

Sets the predefined variable _LastError into the value equal to ERR_USER_ERROR_FIRST + user_error


However, I would suggest you instead just rethink your logic so as not to need an error state.