sures()-准则支持库 [英] Ensures() - guideline support library

查看:122
本文介绍了sures()-准则支持库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何在代码中使用Ensures().如示例,如果我尝试如下使用Ensures() ...

I am trying to understand how to use Ensures() in code. As given in the example, if I tried using Ensures() as follows...

int main(void)
{
    int result = 0;
    // Some calculation
    Ensures(result == 255);
    return 0;
}

如果result变量不等于255,则程序将崩溃,并显示以下输出"terminate called without an active exception".我的问题是如何正确使用Ensures()?

If the result variable is not equal to 255, the program crashes with the following output "terminate called without an active exception". My question is how to use Ensures() properly?

推荐答案

您是否正在使用 Microsoft GSL实现?然后,如果您检查 gsl_assert.h头文件,您将可以看到,如果定义了GSL_TERMINATE_ON_CONTRACT_VIOLATION(默认设置),则Ensures将调用 std::terminate ,它将为您提供错误信息.

Are you using the Microsoft GSL implementation? Then if you check the gsl_assert.h header file you will see that if GSL_TERMINATE_ON_CONTRACT_VIOLATION is defined (which is default) then Ensures will call std::terminate which will give you the error you get.

如果要引发异常(带有文件和行号信息),则需要在包含GSL之前定义GSL_THROW_ON_CONTRACT_VIOLATION.

If you want an exception to be thrown (with file and line-number information) then you need to define GSL_THROW_ON_CONTRACT_VIOLATION before including the GSL.

至于您是否正确使用了Ensures,那么您肯定会使用.

As for if you're using Ensures properly, then yes you are.

这篇关于sures()-准则支持库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆