【发布时间】:2015-03-14 03:12:28
【问题描述】:
我想做这样的玩具程序:
#include <boost/function.hpp>
#include <iostream>
template <typename T>
void func1(T& g) {
std::cout << 1;
}
template <typename T>
void func2(T& g) {
std::cout << 2;
}
int main() {
boost::function<void(int)> f;
int k;
std::cin >> k;
if (k == 1)
f = func1 < int > ;
else
f = func2 < int > ;
}
但是这段代码不起作用,它说“operator=”不清楚。有什么方法可以做这样的事情吗?
【问题讨论】:
-
请发布确切的错误。我在 Coliru 上 can't reproduce it。
-
对不起,错误 C2593 'operator =' is ambiguous
标签: c++ boost function-templates