gpt4 book ai didi

c++ - 获取指向 boost::any::operator= 的指针

转载 作者:行者123 更新时间:2023-11-28 07:25:00 25 4
gpt4 key购买 nike

我想获得指向 boost::any::operator= 的指针,所以我这样做了:

bool(__thiscall boost::any::*func)(const bool&) = &(boost::any::operator=<bool>);

但是现在,编译器说

初始化':无法从'重载函数'转换为'bool (__thiscall boost::any::*)(const bool &)' 范围内具有此名称的函数均不匹配目标类型

我也试过这样做:

bool(__thiscall boost::any::*func)(const bool&) = static_cast<(boost::any::*)(const bool&)>(&(boost::any::operator=<bool>));

但是编译器说:“语法错误:‘(’”在这一行

有人可以帮帮我吗?

附言我在上面的代码中创建了 boost::any 实例

最佳答案

您不能在成员函数指针的赋值中指定参数。这将做到:

#include <iostream>
#include <boost/any.hpp>
int main() {
boost::any any = false;
std::cout << boost::any_cast<bool>(any) << std::endl;
typedef boost::any& (boost::any::*assign_operator)(const bool&);
assign_operator assign = &boost::any::operator =;
(any.*assign)(true);
std::cout << boost::any_cast<bool>(any) << std::endl;
return 0;
}

关于c++ - 获取指向 boost::any::operator= 的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18912311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com