是否有可能避免有关 void 函数返回值的外部引用换行错误
Is there a possibility to avoid the xrefwrap error about void function returning a value?
我有一个像std::vector<std::function<void()>> functions
这样的向量定义,为了存储一个项目,我以这种方式使用一个函数:
template <typename Fun, typename Instance, typename ... Args>
void AddFunction(std::string name, Fun&& fun, Instance* instance, Args&& ... args)
{
/*something is going on here*/
functions.push_back(std::bind(fun, instance, std::forward<Args>(args)...));
/*something is going on here*/
}
问题是有时传递给std::bind
的函数可以返回某种值。我想过使用 lambdas,我尝试了这样的东西
template <typename Fun, typename Instance, typename ... Args>
void AddFunction(std::string name, Fun&& fun, Instance* instance, Args&& ... args)
{
/*something is going on here*/
auto lambda = [&]() -> void
{
fun(std::forward<Args>(args)...);
};
functions.push_back(std::move(lambda));
/*something is going on here*/
}
但是每次我尝试使用AddFunction
都会显示一条错误消息,说term does not evaluate to a function taking n arguments
n
是我传递给AddFunction
的函数所接受的参数数。
是否有一些解决方法,以便即使存储的函数返回值,我也可以存储 std::function<void()>
类型的项目?
两者
functions.push_back(std::bind(fun, instance, std::forward<Args>(args)...));
和
auto lambda = [&]() -> void
{
(instance->*fun)(std::forward<Args>(args)...);
};
functions.push_back(std::move(lambda));
与Visual Studio一起工作得很好。
相关文章:
- 在函数内创建的对象的范围 - 如果在函数外部存储和访问引用,它们是否有效?
- 使用带有 CMake 和 Conan 的外部库的未定义引用
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- C++ 为什么在定义的编译和链接之前引用外部实例的程序
- 如果 copts 不允许系统路径,如何引用外部依赖项使用的系统库?
- 函数 LNK2019 "int __cdecl __scrt_common_main_seh(void)" 中引用的未解析外部符号主错误 (?__scrt_common_main_seh@@YAHXZ
- 函数_wmain中引用未解析的外部符号_RasSetEntryPropertiesW@24
- C++ 链接器错误 LNK 2019 函数中引用的未解析的外部符号
- 如何修复"未解析的外部符号"公共:void__thiscall canoid::getinput(void)"(?Getinput@Canoid@@QAEXXZ) 在函数 _main C++ 中引用
- C 引用C++外部
- 使用静态变量未解析的外部符号/未定义的引用时出错
- 未解析的外部符号__imp_glewInit函数 main 中引用
- 在虚幻引擎中引用外部库时出现运行时错误
- 具有仅在某些情况下引用外部变量的属性的类
- 为什么静态本地对象可以通过指针或外部引用访问?
- 使用指向函数的指针的外部引用时的链接器警告
- 需要帮助为JNI调用构建DLL.未解析的外部引用.Borland编译器
- Eclipse中未定义的外部引用
- 外部引用初始化
- 是否有可能避免有关 void 函数返回值的外部引用换行错误