다음을 통해 공유


function::operator=

Replaces the stored callable object.

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
    A null pointer constant.

  • right
    The function object to copy.

  • fn
    The callable object to wrap.

  • fnref
    The callable object reference to wrap.

설명

The operators each replace the callable object held by *this with the callable object passed as the operand.

예제

 

// 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); 
    } 
 
  

요구 사항

헤더: <기능>

네임스페이스: std

참고 항목

참조

function 클래스

function::function

function::swap