如果我只编写了函数的空实现或部分实现,我喜欢这样做:
... foo(...)
{
// Some unfinished implementation or empty
throw std::runtime_error("Not implemented.");
}
,这样我就不会忘记在使用之前完成实现。只要我不使用它,代码就可以编译并且可以正常工作。
但是,如果
foo()
有 noexcept
,这将导致编译器给出警告或错误。有没有另一种优雅的方法来实现这一目标?
您随时可以终止程序:
... foo(...)
{
log("uninplemented function foo called");
std::terminate();
}