Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't use templates for that at all. Instead of:

    Class * object = new (...);
I do:

    Class * object;
    object = malloc (sizeof Class);
    if (nullptr == object) // ... error handling

    new (object) Class (...);
or if the constructor needs to fail:

    Class * object;
    object = malloc (sizeof Class);
    if (nullptr == object) // ... error handling

    new (object) Class ();
    if (!Class::init (object, ...)) {
        object->~Class ();
        free (object);

        // ...  other error handling
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: