青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

ACG狂人

其實我更愛姐汁...

boost::bind綁定成員函數時,第一個參數傳遞對象的特殊情況

boost::bind(&memberfunction, obj, _1, _2........)類似這樣的用法,我們叫做成員函數綁定,boost庫的文檔中說的很清楚,第一個參數可以是value、pointer和reference,即傳值、傳地址和傳引用都是可以的,所以在一般情況下,下面三種使用bind的形式都是成立的。

class A
{
public:
    
void func();
}
;


A a;
A
& r = a;

boost::bind(
&A::func, a);
boost::bind(
&a::func, &a);
boost::bind(
&a::func, r);

由上面的代碼可以看出,我們可以隨便傳任意一種類對象的形式,函數模板會自動尋找最為匹配的為我們實現。但是有兩種情況是特殊的,即:
1、該對象不可進行拷貝構造函數。
2、該對象不可隨意被析構。
發現這個問題是在我編寫單件模式時的遇見的,當時發現我的單件對象在bind中被析構了一次,這很不尋常,為什么bind會調用第一個參數的析構呢?跟蹤進了boost的源碼才發現,原來所有的參數都會被拷貝一遍,然后析構一遍,這樣一來,我們傳遞參數的時候就會有一些小麻煩了,首先必須保證參數能夠被拷貝而不影響邏輯和數據一致性,其次,參數能夠被析構而不影響邏輯和數據一致性。單件是全局性質的數據,所以絕對不可以析構,那么這種情況的話,我們只好傳遞單件對象的地址,而不能傳遞值或引用。

另:附上出錯問題的代碼如下
class InputDevice
    : 
public EventSource
    , 
public Singleton<InputDevice>
{
public:
    
}
;

class TestUI
    : 
public Singleton<TestUI>
{
public:
    
~TestUI(){
        std::cout
<<"~TestUI"<<std::endl;
    }

    
void processKeyboard(EventArgs& args){
        std::cout
<<"鍵盤響應"<<std::endl;
    }


    
void processMouse(EventArgs& args){
        std::cout
<<"鼠標響應"<<std::endl;
    }

}
;


int _tmain(int argc, _TCHAR* argv[])
{
    
new FrameUpdaterManager;
    
new DelayEventSender;
    
new InputDevice;
    
new TestUI;

    InputDevice::getSingleton().mEventSet.addEvent(
"KeyDown", Event());
    InputDevice::getSingleton().mEventSet.addEvent(
"KeyUp", Event());
    InputDevice::getSingleton().mEventSet.addEvent(
"MouseLDown", Event());
    InputDevice::getSingleton().mEventSet.addEvent(
"MouseLUp", Event());
    InputDevice::getSingleton().mEventSet.addEvent(
"MouseRDown", Event());
    InputDevice::getSingleton().mEventSet.addEvent(
"MouseRUp", Event());


    
//TestUI& ui = TestUI::getSingleton(); // 用此行便會出錯
    TestUI* ui = TestUI::getSingletonPtr();

    
// 出錯開始
    InputDevice::getSingleton().mEventSet["KeyDown"+= boost::bind(&TestUI::processKeyboard, ui, _1);
    InputDevice::getSingleton().mEventSet[
"KeyUp"+= boost::bind(&TestUI::processKeyboard, ui, _1);

    InputDevice::getSingleton().mEventSet[
"MouseLDown"+= boost::bind(&TestUI::processMouse, ui, _1);
    InputDevice::getSingleton().mEventSet[
"MouseLUp"+= boost::bind(&TestUI::processMouse, ui, _1);
    InputDevice::getSingleton().mEventSet[
"MouseRDown"+= boost::bind(&TestUI::processMouse, ui, _1);
    InputDevice::getSingleton().mEventSet[
"MouseRUp"+= boost::bind(&TestUI::processMouse, ui, _1);


    delete TestUI::getSingletonPtr();
    delete InputDevice::getSingletonPtr();
    delete DelayEventSender::getSingletonPtr();
    delete FrameUpdaterManager::getSingletonPtr();
    
return 0;
}

posted on 2009-06-15 22:34 釀妹汁 閱讀(5839) 評論(4)  編輯 收藏 引用 所屬分類: C++

評論

# re: boost::bind綁定成員函數時,第一個參數傳遞對象的特殊情況 2009-06-16 00:14 一個無聊的人

為啥不用boost::mem_fn ?  回復  更多評論   

# re: boost::bind綁定成員函數時,第一個參數傳遞對象的特殊情況 2009-06-16 08:27 董波

6.2. Requirements for Call Wrapper Types
TR1 defines some additional terms that are used to describe requirements for callable types.

First, INVOKE(fn, t1, t2, ..., tN) describes the effect of calling a callable object fn with the arguments t1, t2, ..., tN. Naturally, the effect depends on the type of the callable object. INVOKE is defined as follows:

(t1.*fn)(t2, ..., tN) when fn is a pointer to a member function of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T

((*t1).*fn)(t2, ..., tN) when fn is a pointer to a member function of a class T and t1 is not one of the types described in the previous item

t1.*fn when fn is a pointer to member data of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T

(*t1).*fn when fn is a pointer to member data of a class T and t1 is not one of the types described in the previous item

fn(t1, t2, ..., tN) in all other cases

What this amounts to is that when the callable object is an ordinary function or a pointer to an ordinary function, INVOKE means to call that function, passing the rest of the arguments to the function call. When the callable object is a pointer to member, the next argument refers to the object that it should be applied to. That argument is the object itself, a reference to the object, a pointer to the object, or some kind of smart pointer that points to the object. The rest of the arguments are passed to the function call.

Second, INVOKE_R(fn, t1, t2, ..., tN, Ret) describes the effect of calling a callable object fn with an explicit return type, Ret. It is defined as INVOKE(fn, t1, t2, ..., tN) implicitly converted to Ret.[5]

[5] In the TR, this metafunction is named INVOKE; although I'm one of the people responsible for this name overloading, I've now concluded that it's too clever and shouldn't be used.

Third, some call wrapper types have a weak result type; this means that they have a nested member named result_type that names a type determined from the call wrapper's target type, Ty.

If Ty is a function, reference to function, pointer to function, or pointer to member function, result_type is a synonym for the return type of Ty

If Ty is a class type with a member type named result_type, result_type is a synonym for Ty::result_type

Otherwise, result_type is not defined[6]

[6] That is, not defined as a consequence of having a weak result type. Some call wrapper types have a weak result type in certain circumstances, have a specific type named result_type

A few examples will help clarify what this rather dense text means:

struct base {
void f();
int g(double);
int h(double,double);
};
struct derived : base {
};

base b;
derived d;
base& br = d;



With these definitions, rule 1 gives the following meanings to these uses of INVOKE .

Phrase
Meaning

INVOKE (&base::f, b)
(b.*f)()

INVOKE (&base::g, d, 1.0)
(d.*f)(1.0)

INVOKE (&base::h, br, 1.0, 2.0)
(br.*f)(1.0, 2.0)





That is, the pointer to member function is called on the object or reference named by t1:

derived *dp = new derived;
base *bp = dp;
shared_ptr<base> sp(bp);



With these additional definitions, rule 2 gives the following meanings to these uses of ( INVOKE):

Phrase
Meaning

INVOKE (&base::f, bp)
((*bp).*f)()

INVOKE (&base::g, dp, 1.0)
((*dp).*f)(1.0)

INVOKE (&base::h, sp, 1.0, 2.0)
((*sp).*f)(1.0, 2.0)





That is, the pointer to member function is called on the object that the argument t1 points to. Since it uniformly dereferences that argument, the rule works for any type whose operator* returns a reference to a suitable object. In particular, the rule works for shared_ptr objects.

Rules 3 and 4 give similar meanings to INVOKE uses that apply pointers to member data:

void func(base&);
struct fun_obj {
void operator()() const;
bool operator()(int) const;
};
fun_obj obj;



With these additional definitions, rule 5 gives the following meanings to these uses of INVOKE:

Phrase
Meaning

INVOKE (func, d)
func(d)

INVOKE (obj)
obj()

INVOKE (obj, 3)
obj(3)


  回復  更多評論   

# re: boost::bind綁定成員函數時,第一個參數傳遞對象的特殊情況 2009-06-16 23:25 wp

文檔上有說明  回復  更多評論   

# re: boost::bind綁定成員函數時,第一個參數傳遞對象的特殊情況 2009-06-19 14:49

哎!我沒耐心看完文檔,有點操之過急了,呵呵,得接受這個教訓  回復  更多評論   

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品草莓在线免费观看| 国产精品久久波多野结衣| 国产一区视频观看| 欧美制服丝袜| 久久不射2019中文字幕| 韩国精品在线观看| 欧美国产日本在线| 欧美精品久久久久a| 亚洲永久视频| 欧美亚洲免费| 亚洲激情成人网| 夜夜爽夜夜爽精品视频| 国产精品va在线| 久久久久久一区二区| 久久久噜噜噜| 亚洲免费在线精品一区| 欧美在线一区二区| 亚洲精品精选| 亚洲一区二区成人在线观看| 经典三级久久| 一区二区欧美视频| 影音先锋成人资源站| 亚洲欧洲日本mm| 国产精品久久91| 欧美成年视频| 国产精品久久国产三级国电话系列 | 蜜臀99久久精品久久久久久软件| 免费日韩成人| 久久av在线看| 欧美日韩精品一区二区三区四区 | 欧美在线首页| 欧美成人性生活| 欧美一级网站| 欧美精品在线观看播放| 久久av最新网址| 欧美日韩亚洲视频| 可以看av的网站久久看| 国产精品高潮呻吟久久av无限| 乱人伦精品视频在线观看| 国产精品成人免费精品自在线观看| 久久综合中文| 国产精品久久久久久影视| 亚洲国产精品成人综合色在线婷婷 | 欧美一级理论性理论a| 日韩一级免费| 欧美a一区二区| 久久久久久久性| 国产精品免费观看视频| 最新国产成人av网站网址麻豆| 国产综合色在线视频区| 亚洲图片在区色| 亚洲婷婷综合色高清在线 | 亚洲桃花岛网站| 99国内精品久久| 欧美电影免费观看大全| 免费久久精品视频| 狠狠色噜噜狠狠狠狠色吗综合| 亚洲网站在线| 亚洲综合精品| 国产精品女主播一区二区三区| 亚洲精品国产日韩| 99亚洲一区二区| 欧美另类一区| 亚洲精品网站在线播放gif| 亚洲人成77777在线观看网| 久久在线精品| 亚洲福利国产| 日韩一级欧洲| 欧美日韩视频专区在线播放| 亚洲免费成人| 亚洲永久免费视频| 国产精品综合视频| 亚洲欧洲av一区二区三区久久| 香蕉乱码成人久久天堂爱免费 | 在线不卡中文字幕| 久久免费少妇高潮久久精品99| 久久青草福利网站| 在线精品视频免费观看| 久久久久久久久久久久久女国产乱| 久久深夜福利免费观看| 在线观看一区| 欧美精品日韩一区| 妖精成人www高清在线观看| 亚洲尤物影院| 国产亚洲精品成人av久久ww| 久久久久国产精品一区三寸| 亚洲国产影院| 亚洲影音一区| 狠狠综合久久| 欧美欧美全黄| 午夜视频一区二区| 欧美成人午夜视频| 中国日韩欧美久久久久久久久| 国产精品国色综合久久| 欧美影视一区| 欧美国产精品中文字幕| 亚洲天堂第二页| 一区二区在线视频| 欧美激情视频在线播放 | 亚洲精品日韩在线| 亚洲欧美日韩一区在线| 激情综合自拍| 国产精品99免费看| 欧美怡红院视频一区二区三区| 欧美激情成人在线视频| 亚洲影视九九影院在线观看| 在线成人av.com| 国产精品草莓在线免费观看| 欧美一区二区三区在线免费观看 | 中国成人黄色视屏| 国产在线播精品第三| 欧美片第一页| 久久只精品国产| 亚洲一区综合| 99re6这里只有精品| 开心色5月久久精品| 亚洲一区二区高清| 亚洲人成绝费网站色www| 国产欧美日韩一区二区三区在线观看| 久久亚洲综合色| 欧美在线啊v| 一区二区三区成人| 亚洲大片免费看| 久久亚洲午夜电影| 午夜激情综合网| 亚洲一区视频在线| 亚洲精选一区二区| 亚洲国产精品123| 国产一区二区三区久久久| 国产精品magnet| 欧美日韩一区二区在线视频| 你懂的网址国产 欧美| 久久久国产一区二区三区| 亚洲欧美激情在线视频| 亚洲图片你懂的| 亚洲深夜av| 亚洲一区二区少妇| 这里只有精品丝袜| 亚洲图片你懂的| 亚洲一区久久| 亚洲欧美日韩成人| 亚洲欧美另类国产| 午夜日韩视频| 久久本道综合色狠狠五月| 欧美怡红院视频一区二区三区| 亚洲欧美国产另类| 亚欧成人在线| 久久久九九九九| 噜噜噜噜噜久久久久久91| 久久躁狠狠躁夜夜爽| 欧美成人在线网站| 欧美日韩久久不卡| 欧美三级第一页| 国产农村妇女毛片精品久久麻豆| 欧美性事在线| 国产亚洲毛片在线| 1024日韩| 一本久道久久综合狠狠爱| 亚洲性视频网址| 久久超碰97人人做人人爱| 久久一区二区三区国产精品| 免费观看日韩| 亚洲国产三级网| 一区二区高清在线观看| 亚洲一区二区不卡免费| 久久精品在线观看| 欧美成人高清视频| 国产精品久久久久国产精品日日| 国产精品综合av一区二区国产馆| 国产一本一道久久香蕉| 亚洲黑丝在线| 亚洲影音一区| 鲁鲁狠狠狠7777一区二区| 亚洲人成免费| 欧美一区二区高清| 欧美www视频| 国产视频精品网| 亚洲伦理精品| 欧美影院视频| 亚洲高清免费| 欧美亚洲日本国产| 欧美精品一区二区三区在线播放| 国产精品嫩草99av在线| 黄色欧美成人| 亚洲在线中文字幕| 欧美国产欧美亚洲国产日韩mv天天看完整| 亚洲人成7777| 久久欧美中文字幕| 国产精品欧美在线| 亚洲欧洲在线免费| 久久国产欧美日韩精品| 亚洲人成网站在线播| 欧美一区二区三区免费大片| 免播放器亚洲一区| 国产一区二区三区日韩| 亚洲天堂成人在线观看| 欧美高清视频免费观看| 午夜伦理片一区| 欧美日韩国内自拍| 亚洲高清视频在线观看|