C++ 用户自定义类型转换失败

C++ User-defined type conversion failure

template<typename T>
class Pack
{
private:
    std::function<T()> _Func = nullptr;
public:
    Pack()
    {
    }
    Pack(std::function<T()> func)
        : _Func(func)
    {
    }
    ~Pack()
    {
    }

    operator T()
    {
        return _Func();
    }
};

我用的是operator T,我想隐式调用_Func,但我什至不能显式调用。看似正确但实际上错误 C2440 @MSVC。我以两种方式使用它:

  1. class 的静态成员(成功);

  2. class 的成员(失败)

(不知道有没有关系)

我真的很想知道为什么它以两种方式执行,更重要的是,我如何将它作为非静态成员放入我的 class 并成功调用 operator T

class的成员:

struct test
{
    test()
    {
        p_ = Pack<int>(std::bind(&test::foo, *this));
    }

    int foo()
    {
        std::cout << "test::foo" << std::endl;
        return 5;
    }

    Pack<int> p_;
};

int main()
{
    test t;
    int x = t.p_;

    return 0;
}

这在 VS 2013 EE 上运行良好。