【发布时间】:2021-11-02 07:34:27
【问题描述】:
我有:
class image {
public:
linked_list<int, int> UnLabeledList;
explicit image(int Segments) {//some code}
};
链表的C'tor在哪里:
linked_list() {
total_nodes = 0;
first = new node<S, T>{}; //Dummy
first->height = NOT_INIT;
last = first;
}
如何检测这条线路是否失败? linked_list<int, int> UnLabeledList;
它在任何函数之外,所以我不能尝试并捕捉......
【问题讨论】:
-
您可以使用函数尝试块 "...函数尝试块将一系列 catch 子句与整个函数体以及 成员初始值设定项相关联列表(如果在构造函数中使用)..."请参阅此处的示例en.cppreference.com/w/cpp/language/function-try-block
标签: c++ class try-catch new-operator allocation