Interrupting a constructor

Hi,
While writing a code, I just thought if this is possible.

Say in a copy constructor (or any constructor) I want a condition on the element it is being constructed with (say a boolean). I want to be able to construct the object of the class based on whether the boolean is true or false. If true construct otherwise don't and that means the object shouldn't be available.

Is it possible to do so within the constructor of the same class ?

Sincerely,
Neeraj
I don't think this is possible, but I don't really understand what you're saying. Do you mean something like this:
1
2
3
4
5
6
class A {
    A(bool cons);
};
A::A(bool cons) {
    if(!cons) abort_construction;
}

Then in use code:
1
2
3
A a(true);
A b(var);
a = b; // invalid is var is false because b was never constructed, otherwise OK? 

If so, it's definitely impossible.
Topic archived. No new replies allowed.