Try-Catch std::bad_alloc outside function?

  allocation, c++, class, new-operator, try-catch

I have:

class image {
public:
    linked_list<int, int> UnLabeledList;

    explicit image(int Segments) {//some code}
};

Where the C’tor of linked list is:

linked_list() {
    total_nodes = 0;
    first = new node<S, T>{}; //Dummy
    first->height = NOT_INIT;
    last = first;
}

How can I detect if this line fails? linked_list<int, int> UnLabeledList;

it’s outside any function so I can’t do try and catch…

Source: Windows Questions C++

LEAVE A COMMENT