function::operator=
取代儲存可呼叫的物件。
function& operator=(null_ptr_type npc);
function& operator=(const function& right);
template<class Fty>
function& operator=(Fty fn);
template<class Fty>
function& operator=(reference_wrapper<Fty> fnref);
參數
npc
null 指標常數。right
要複製的函式物件。fn
要包裝的可呼叫的物件。fnref
在一組可呼叫的物件參考。
備註
運算子不同的名稱為傳遞至的運算元的可呼叫的物件取代 *this 持有的可呼叫的物件。
範例
// std_tr1__functional__function_operator_as.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
int neg(int val)
{
return (-val);
}
int main()
{
std::function<int (int)> fn0(neg);
std::cout << std::boolalpha << "empty == " << !fn0 << std::endl;
std::cout << "val == " << fn0(3) << std::endl;
std::function<int (int)> fn1;
fn1 = 0;
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
fn1 = neg;
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
std::cout << "val == " << fn1(3) << std::endl;
fn1 = fn0;
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
std::cout << "val == " << fn1(3) << std::endl;
fn1 = std::cref(fn1);
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
std::cout << "val == " << fn1(3) << std::endl;
return (0);
}
需求
標題: <functional>
命名空間: std