C++ 如何在ChaiScript中注册重载模板成员函数?

C++ 如何在ChaiScript中注册重载模板成员函数?,c++,templates,c++14,overloading,chaiscript,C++,Templates,C++14,Overloading,Chaiscript,我有下一个定义类: class MyType { public: template <typename T> MyType& put(const std::string& s, T&& val); template <typename T> MyType& put(size_t pos, T&& val); template <typename M, typename

我有下一个定义类:

class MyType {
public:
    template <typename T>
    MyType& put(const std::string& s, T&& val);

    template <typename T>
    MyType& put(size_t pos, T&& val);

    template <typename M, typename T, typename = std::enable_if_t<std::is_same<MyType, std::decay_t<M>>::value>>
    MyType& put(const M& o, T&& val);
}
但是没有编译,因为有几个候选函数。

您编写了:

static_cast<MyType& (MyType::*)(const std::string&, uint64_t)>(
    &MyType::put<uint64_t>)

@chema989 1它被称为转发参考。如果你传入一个左值,你不是在调用put,而是在调用put。这是一个不同的实例化。是的,我必须在ChaiScript中注册每个不同的实例化。谢谢你,巴里。
static_cast<MyType& (MyType::*)(const std::string&, uint64_t)>(
    &MyType::put<uint64_t>)
template <typename T>
MyType& put(const std::string& s, T&& val);
static_cast<MyType& (MyType::*)(const std::string&, uint64_t&&)>(
    &MyType::put<uint64_t>)
//                                                  ~~~~~~~~~~~