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

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 釀妹汁 閱讀(5820) 評論(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>
            中文网丁香综合网| 欧美日韩成人一区二区三区| 欧美在线一区二区| 亚洲一区在线免费观看| 亚洲女ⅴideoshd黑人| 99精品99久久久久久宅男| 日韩午夜三级在线| 99热精品在线| 亚洲尤物在线| 久久九九久精品国产免费直播| 久久精品视频在线播放| 免播放器亚洲| 亚洲激情网址| 99视频一区二区三区| 亚洲一区三区电影在线观看| 欧美一区二区三区视频免费播放| 欧美有码视频| 欧美激情视频在线播放| 国产精品久久久久久久久借妻| 国产欧美一区二区精品婷婷| 亚洲第一在线| 亚洲欧美日韩在线高清直播| 久久夜色精品国产亚洲aⅴ| 亚洲国产精品女人久久久| 正在播放亚洲一区| 久久综合狠狠综合久久激情| 欧美日精品一区视频| 国模私拍一区二区三区| 一本色道久久加勒比88综合| 久久久久免费视频| 一区二区日韩精品| 欧美 日韩 国产在线 | 久久综合激情| 一本色道久久88亚洲综合88| 亚洲欧美网站| 国产精品久久久久毛片软件 | 久久久五月婷婷| 国产精品xvideos88| 亚洲欧洲在线播放| 久热国产精品| 午夜欧美理论片| 国产精品扒开腿做爽爽爽视频| 亚洲高清毛片| 久热精品视频在线免费观看| 亚洲一区在线免费观看| 欧美久久久久久久| 亚洲欧洲三级电影| 麻豆成人在线观看| 久久国产乱子精品免费女| 国产精品丝袜91| 亚洲一区尤物| 一区二区三区视频在线 | 欧美精品在线免费观看| 亚洲丁香婷深爱综合| 久久综合99re88久久爱| 欧美一区二区三区播放老司机 | 久久精品观看| 亚洲欧美日韩直播| 欧美天堂在线观看| 一区二区欧美视频| 亚洲精品中文字幕有码专区| 欧美顶级少妇做爰| 亚洲美女中文字幕| 亚洲精品国产精品国自产观看| 免费观看成人鲁鲁鲁鲁鲁视频| 一区二区三区无毛| 欧美ed2k| 欧美激情视频网站| 亚洲网友自拍| 宅男在线国产精品| 国产精品视频免费观看| 欧美一区二区三区四区高清| 国产精品99久久久久久www| 国产精品播放| 欧美自拍偷拍午夜视频| 欧美在线看片| 最新中文字幕亚洲| 日韩午夜剧场| 国产女主播一区| 裸体素人女欧美日韩| 欧美不卡视频一区发布| 中日韩高清电影网| 午夜精品一区二区三区四区| 狠狠入ady亚洲精品| 欧美国产日韩在线| 欧美视频在线一区| 久热精品在线| 欧美视频一区二区三区| 久久国产欧美精品| 欧美韩日一区二区| 亚洲免费av观看| 国产精品午夜在线观看| 久久人人爽国产| 欧美精彩视频一区二区三区| 亚洲影院高清在线| 久久亚洲一区二区| 亚洲无线视频| 久久久久久自在自线| 一区二区三区久久久| 久久国内精品自在自线400部| 亚洲精品麻豆| 欧美一区免费| 亚洲一区二区黄| 久久综合久久综合久久| 午夜精品久久久久久久久久久| 久久亚裔精品欧美| 性色av一区二区三区| 狂野欧美性猛交xxxx巴西| 亚洲欧美大片| 欧美精品在线一区| 另类av一区二区| 国产精品热久久久久夜色精品三区| 免费观看成人网| 国产热re99久久6国产精品| 亚洲人成高清| 亚洲国产乱码最新视频| 欧美一级视频| 亚洲欧美日韩精品久久亚洲区 | 欧美日韩亚洲国产精品| 久久琪琪电影院| 国产精品一级久久久| 亚洲精品一区二区在线观看| 一区二区视频欧美| 午夜精品一区二区三区电影天堂 | 夜夜精品视频| 毛片精品免费在线观看| 久久午夜国产精品| 国产一级精品aaaaa看| 亚洲特黄一级片| 亚洲香蕉成视频在线观看| 欧美激情综合亚洲一二区| 欧美福利专区| 亚洲欧洲日韩在线| 欧美激情一区二区三区在线视频观看 | 一区二区三区产品免费精品久久75| 亚洲国产日韩一区| 久久综合久久美利坚合众国| 久久一区二区三区av| 国产自产女人91一区在线观看| 亚洲欧美在线x视频| 欧美影院成年免费版| 国产麻豆精品在线观看| 午夜视频一区二区| 久久狠狠一本精品综合网| 国产色产综合产在线视频| 在线精品视频免费观看| 亚洲理论在线观看| 伊甸园精品99久久久久久| 午夜视频一区在线观看| 欧美中文在线免费| 国产一区香蕉久久| 久久久亚洲精品一区二区三区| 麻豆精品精华液| 亚洲黄一区二区三区| 欧美电影免费观看高清| 99国产精品视频免费观看| 亚洲欧美日韩成人| 国产婷婷一区二区| 久久久久久久久一区二区| 欧美不卡视频一区| 一本久久a久久精品亚洲| 国产精品色在线| 久久久久久综合| 亚洲精品视频在线播放| 亚洲欧美日韩国产中文在线| 国产一区二区精品久久| 男人的天堂成人在线| 99亚洲精品| 久久久亚洲午夜电影| 9久re热视频在线精品| 国产精品自拍视频| 嫩草国产精品入口| 亚洲一区在线免费观看| 欧美高清视频一二三区| 亚洲一级影院| 在线视频观看日韩| 欧美性猛交xxxx乱大交蜜桃| 欧美制服丝袜| 日韩视频在线观看| 久久在精品线影院精品国产| 亚洲精品综合精品自拍| 国产欧美日韩综合一区在线播放| 久久一区二区视频| 亚洲制服av| 亚洲日本va在线观看| 久久久国产精品一区二区三区| 日韩一级在线观看| 在线观看欧美视频| 国产欧美精品久久| 欧美日韩国产色站一区二区三区| 久久国产精品99久久久久久老狼| 亚洲精品综合在线| 欧美国内亚洲| 久久亚洲精品一区二区| 亚洲欧美日韩天堂一区二区| 日韩视频免费在线观看| 亚洲第一中文字幕| 狠狠色狠狠色综合日日小说| 国产精品无码永久免费888| 欧美日韩午夜|