错误 C2694 “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数

目录

Logger 配置方法,测试ok:


tensorrt c++报错:

错误    C2694    “void Logger::log(nvinfer1::ILogger::Severity,const char *)”: 重写虚函数的限制性异常规范比基类虚成员函数

问题:“Looser throw specifier for ‘xxxxxxxxxx’”
例子:
looser throw specifier for ‘virtual void Logger::log(nvinfer1::ILogger::Severity, const char*)’

解决:参考链接
在函数中加入noexcept
因为,在tensorrt8.0版本中函数的定义是:

void Logger::log(Severity severity, const char* msg) noexcept


所以自己的报错的函数对应也改为:

 virtual void log(Severity severity, const char* msg) noexcept override;

我的修改后的代码: 

    void log(Severity severity, const char* msg) noexcept override
    {
        LogStreamConsumer(mReportableSeverity, severity) << "[TRT] " << std::string(msg) << std::endl;
    }

Logger 配置方法,测试ok:

tensorrt8.2版本:

class Logger : public ILogger
{
	//void log(Severity severity, const char* msg) override
	void log(Severity severity, nvinfer1::AsciiChar const* msg) noexcept override
	{
		// suppress info-level messages
		if (severity <= Severity::kWARNING)
			std::cout << msg << std::endl;
	}
} ggLogger;

旧版本报错:

error: ‘nvinfer1::AsciiChar’ has not been declared

解决方法:

class Logger : public ILogger
{
	void log(Severity severity, const char* msg) override
	//void log(Severity severity, nvinfer1::AsciiChar const* msg) noexcept override
	{
		// suppress info-level messages
		if (severity <= Severity::kWARNING)
			std::cout << msg << std::endl;
	}
} ggLogger;


其他报错Looser throw specifier的同样解决方法,增加noexcept。

问题2:nvinfer plugin调用
参考链接:https://blog.csdn.net/XCCCCZ/article/details/121301106
报错如下:yololayer.h(54): warning: function “nvinfer1::IPluginV2::enqueue(int32_t, const void *const *, void *const *, void *, cudaStream_t)” is hidden by “nvinfer1::YoloLayerPlugin::enqueue” – virtual function override intended?

yololayer.cu(156): error: object of abstract class type “nvinfer1::YoloLayerPlugin” is not allowed:

pure virtual function “nvinfer1::IPluginV2::enqueue” has no overrider

yololayer.cu(299): error: object of abstract class type “nvinfer1::YoloLayerPlugin” is not allowed:
pure virtual function “nvinfer1::IPluginV2::enqueue” has no overrider

yololayer.cu(308): error: object of abstract class type “nvinfer1::YoloLayerPlugin” is not allowed:
pure virtual function “nvinfer1::IPluginV2::enqueue” has no overrider

解决方法:将virtual int enqueue(int batchSize, const voidconst * inputs, void** outputs, void workspace, cudaStream_t stream) override;改成virtual int32_t enqueue(int32_t batchSize, void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept;
————————————————
版权声明:本文为CSDN博主「云秋水慢」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yunqiushuiman/article/details/125477748

这篇讲的差不多:

error: looser throw specifier for ‘virtual void Logger::log(nvinfer1::ILogger::Severity, const_lxx1481932986的博客-CSDN博客

  • 11
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值