【发布时间】:2017-03-01 12:23:38
【问题描述】:
我向现有类添加了一个重载方法,这会导致我们的单元测试出现编译错误。
我已经用以下代码复制了这个问题:
#include <type_traits>
#include <string>
class Foo
{
public:
Foo() {};
int bar(const std::string & s) {return 1;};
int bar(const std::string & s, long l) {return 2;};
int bar2(const std::string & s) {return 3;};
};
int main()
{
// compiles
std::is_same<std::result_of<decltype(&Foo::bar2)(Foo, const std::string &)>::type, int>::value;
// does not compile
std::is_same<std::result_of<decltype(&Foo::bar)(Foo, const std::string &)>::type, int>::value;
return 0;
}
我需要对未编译的行进行哪些更改,以便测试重载方法的返回?
【问题讨论】:
-
std::is_same<decltype(std::declval<Foo&>().bar("")), int>::value -
@Muscampester 谢谢,接受的答案帮助我理解了上面 Piotr 的评论
-
@PiotrSkotnicki 我认为将评论作为答案发布是合理的。
标签: c++ overloading result-of