这是我面临的问题:我在一个类中有一个重载函数,并且我想将其重载之一作为参数传递。但是这样做时,出现以下错误:
"no suitable constructor exists to convert from <unknown-type> to std::function<...>"
Run Code Online (Sandbox Code Playgroud)
这是一个代码示例来说明这一点:
#include <functional>
#include <string>
class Foo
{
private:
int val1 , val2;
};
class Bar
{
public:
void function ( ) {
//do stuff;
Foo f;
function ( f );
}
void function ( const Foo& f ) {
//do stuff
}
private:
//random attribute
std::string str;
};
void otherFunction ( std::function<void ( Bar& , const Foo& ) > function ) {
Bar b;
Foo f;
function(b,f);
} …Run Code Online (Sandbox Code Playgroud) 以前可能有人问过这个问题,但我找不到任何东西..
在 Go 中,你可以做这样的事情
v1 := 3
v2 := 4
if v := v1 - v2; v < 4 {
// use v
}
Run Code Online (Sandbox Code Playgroud)
在 Rust 中,我找不到用if let绑定来做到这一点的方法
let v1 = 3;
let v2 = 4;
// able to match an exact value
if let v @ 4 = v1 - v2 {}
// but unable to match a range of value like in a `match` block
if let v @ (0..4) = v1 - v2 {}
if …Run Code Online (Sandbox Code Playgroud)