【问题标题】:Conversion Error from 'unsigned __int64' to 'unsigned __int64 *' - Pybind11从'unsigned __int64'到'unsigned __int64 *'的转换错误 - Pybind11
【发布时间】:2018-06-12 09:07:40
【问题描述】:

下载后https://github.com/pybind/pybind11/archive/v2.2.3.zip 并创建一个简单的 cpp 文件:

#include <pybind11/pybind11.h>

int add(int i, int j) { return i + j; }

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring
    m.def("add", &add, "A function which adds two numbers");
}

我收到此错误

Error C2446 '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *' in c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector line 2326

有谁知道这可能指的是什么,以及可能如何解决它?


根据要求,这里是完整的错误日志:

1>------ Rebuild All started: Project: Test_CreatePythonBindings, Configuration: Debug x64 ------
1>example.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): error C2446: '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2325): note: while compiling class template member function 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2545): note: see reference to function template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2490): note: see reference to class template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3094): note: see reference to class template instantiation 'std::_Vb_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3093): note: while compiling class template member function 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)'
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\pybind11-2.2.3\include\pybind11\pybind11.h(513): note: see reference to function template instantiation 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)' being compiled
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\pybind11-2.2.3\include\pybind11\cast.h(1806): note: see reference to class template instantiation 'std::vector<bool,std::allocator<_Ty>>' being compiled
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>Done building project "Test_CreatePythonBindings.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

【问题讨论】:

  • 切换到下方窗格中的“构建”视图并将文本粘贴到此处。那里会有更多信息。这个错误源于向量实现,但不是发生的地方。
  • 另外,尝试生成minimal reproducible example(注意那里的“完成”)。
  • @BJovke 添加了完整的输出,希望对您有所帮助。
  • 是的,这有帮助,错误在“cast.h”中。我得看看。
  • 实际上错误在“pybind11.h”中,但您发布的错误日志中的行与您在问题中引用的 ZIP 文件中的行不匹配。所以代码可能不一样。您可以重新下载 ZIP 文件,再次使用它构建并再次发布错误吗?

标签: c++ c++11 type-conversion pybind11


【解决方案1】:

这似乎是与

相关的 VS 2017 问题
  std::vector<bool>

这里提出了单独的问题: Pushback on vector<bool> fails - VS 2017

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 2016-12-20
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多