0

boost::any::operator= へのポインターを取得したいので、次のようにしました。

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

しかし今、コンパイラは言う

初期化中 : 'overloaded-function' から 'bool (__thiscall boost::any::* )(const bool &)' に変換できません

私もこのようにしようとしました:

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

しかし、この行に「構文エラー: '('」というコンパイラがあります。

誰か助けてくれませんか?

PS上記のコードでboost::anyのインスタンスを作成します

4

1 に答える 1

1

メンバ関数ポインタの代入では引数を指定できません。これはそれを行います:

#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;
}
于 2013-09-20T09:41:19.370 に答える