小编Hir*_*aCC的帖子

模板参数不明确:无法推断模板参数

我正在做一些看起来像这样的包装器:

#include <iostream>

template<class T, class Value>
void Apply(void (T::*cb)(Value), T* obj, Value v)
{
    (obj->*cb)(v);
}

class Foo
{
public:
    void MyFunc(const int& i)
    {
        std::cout << i << std::endl;
    }

    const int& GetValue()
    {
        return i_;
    }

private:
    int i_ = 14;
};

int main()
{
    Foo f;
    Apply(&Foo::MyFunc, &f, f.GetValue());
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

  • Apply:找不到匹配的重载函数.
  • void Apply(void (__thiscall T::* )(Value),T *,Value):模板参数Value不明确,可能是intconst int &.
  • void Apply(void (__thiscall T::* )(Value),T *,Value):无法推断Value …

c++ templates ambiguous ambiguous-call template-argument-deduction

9
推荐指数
1
解决办法
839
查看次数

VS2017 C++标准库模块

VS2017可以安装标准库模块.

实际上Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\ifc\有ifc模块定义文件和std.libx86/x64和Debug/Release.我们如何使用它们?你如何与他们联系?这些标准模块到底有哪些?

c++ module visual-studio-2017

7
推荐指数
1
解决办法
4283
查看次数