未定义对“ boo()” collect2的引用:错误:ld返回1退出状态

时间:2019-03-20 03:23:05

标签: c++

我有用于异常错误的此示例代码,对于我来说,这对典型情况似乎是正确的,除了"bool failed"周围的花括号外,但我得到了undefined reference to 'boo()' error。我不确定为什么boo()已经声明

#include <iostream>
#include <stdexcept>

bool boo();

// throws std::runtime_error on error
void foo()
{
  if(!boo())
    throw std::runtime_error {"bool failed"};
}

int main()
{
    try {
        foo();
    }
    catch (const std::runtime_error& ex) {
        std::cout << "Unhandled std::exception caught: " << ex.what() << "\n";
    }
}

0 个答案:

没有答案
相关问题