错误:"template< class _Tp,class _Dp>"模板参数列表中参数1的类型/值不匹配.class std :: unique_ptr’ [英] error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’

查看:103
本文介绍了错误:"template< class _Tp,class _Dp>"模板参数列表中参数1的类型/值不匹配.class std :: unique_ptr’的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始之前,我是C ++ 11的一个完全菜鸟,几年前就使用过C.

Before we start, I am a complete noob in C++11, had used C several years ago.

我正在尝试使用pybind11编写C ++ 11代码的python绑定,并且遇到主题错误.我基本上是在遵循Nvidia的指南人,并停留在此错误.有什么好心的人能指出我正确的方向吗?

I am trying to write a python binding of a C++11 code using pybind11 and is getting a subjected error. I am basically following this guide from Nvidia people and is stuck at this error. Can any nice soul point me to the right direction?

定义:

template<int zoom_factor>
class UpSamplePlugin: public nvinfer1::IPluginExt
{
public:
    UpSamplePlugin() {}

    // Create the plugin at runtime from a byte stream.
    UpSamplePlugin(const void* buffer, size_t size)
    {
        assert(size == sizeof(mInputDims)); // assert datatype of input
        mInputDims = *reinterpret_cast<const nvinfer1::Dims*>(buffer);
    }
...
}

致电:

py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
        // Bind the normal constructor as well as the one which deserializes the plugin
        //.def(py::init<const nvinfer1::Weights*, int>())
        .def(py::init<const void*, size_t>())
    ;

错误:

/media/.../plugin/pyUpSample.cpp: In function ‘void pybind11_init_upsampleplugin(pybind11::module&)’:
/media/.../plugin/pyUpSample.cpp:13:90: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’
     py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
                                                                                          ^
/media/.../plugin/pyUpSample.cpp:13:90: note:   expected a type, got ‘UpSamplePlugin’

推荐答案

没有名为 UpSamplePlugin 的类型,这只是一个模板.因此,您必须执行类似 UpSamplePlugin< T> 的操作.您的情况应该是 UpSamplePlugin< zoom_factor>

There is no type called UpSamplePlugin, this is just a template. So you must do something like UpSamplePlugin<T>. In your case it should be UpSamplePlugin<zoom_factor>

尝试以下代码, ,如果此声明位于模板内:

Try the following code, if this declaration is inside the template:

py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
    // Bind the normal constructor as well as the one which deserializes the plugin
    //.def(py::init<const nvinfer1::Weights*, int>())
    .def(py::init<const void*, size_t>())
;

编译器将创建"与 UpSamplePlugin< zoom_factor> 相对应的新类型.

The compiler will "create" a new type that corresponds to UpSamplePlugin<zoom_factor>.

如果它不在模板内:

If it is not inside the template:

创建另一个模板(可以是模板函数),可以使用zoom_factor将该模板调用为任何常量类型:

Create another template (it could be a template function), that can be called with the zoom_factor to be any constant type:

template<int zoom_factor>
void doSomething() {
    py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
    // Bind the normal constructor as well as the one which deserializes the plugin
    //.def(py::init<const nvinfer1::Weights*, int>())
    .def(py::init<const void*, size_t>())
;    
}

然后,您可以使用任何 COMPILE TIME KNOWN zoom_factor

Then you can call this function with any COMPILE TIME KNOWN zoom_factor

这篇关于错误:"template&lt; class _Tp,class _Dp&gt;"模板参数列表中参数1的类型/值不匹配.class std :: unique_ptr’的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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