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

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>
            亚洲国产高清视频| 亚洲一区二区三区在线| 久久精品国产99国产精品澳门| 9人人澡人人爽人人精品| 欧美日韩中文字幕在线| 午夜精品久久久| 久久精品亚洲精品| 亚洲激情国产精品| 99在线热播精品免费99热| 国产精品综合网站| 美日韩丰满少妇在线观看| 欧美国产成人精品| 欧美亚洲午夜视频在线观看| 久久精品理论片| 亚洲免费av电影| 午夜精品久久久久久久99樱桃 | 欧美国产亚洲另类动漫| 欧美精品自拍| 久久精品视频免费| 欧美国产一区二区| 欧美中文字幕| 欧美美女喷水视频| 久久久国产视频91| 欧美日韩国产色综合一二三四| 欧美一区二区精品久久911| 久久综合中文| 欧美一区二区在线播放| 欧美高清成人| 久久色在线播放| 国产精品国产三级国产专区53 | 亚洲二区免费| 国产亚洲毛片在线| 99精品免费网| 亚洲国产成人av好男人在线观看| 一区二区电影免费在线观看| 亚洲电影一级黄| 欧美伊人久久大香线蕉综合69| 日韩一二三区视频| 久久婷婷影院| 久久精品视频免费| 国产精品一区二区三区四区 | 欧美激情视频在线免费观看 欧美视频免费一 | 亚洲伦理久久| 亚洲国产精品黑人久久久 | 亚洲精品视频二区| 亚洲国产另类精品专区| 香蕉成人久久| 羞羞色国产精品| 国产精品99免视看9| 亚洲国产婷婷香蕉久久久久久99| 国产一区视频观看| 午夜视频精品| 欧美一区二区三区在线播放| 欧美特黄一级| 中日韩男男gay无套| 亚洲午夜av电影| 欧美日韩国产a| 亚洲精品一区二区三区樱花| 日韩一级免费| 欧美日韩国产限制| 日韩视频在线一区二区三区| 99v久久综合狠狠综合久久| 欧美暴力喷水在线| 亚洲国产老妈| 一本大道久久a久久精二百| 欧美激情在线| 一区二区三区久久网| 亚洲一区二区网站| 国产精品美女久久久| 亚洲在线视频| 久久婷婷影院| 亚洲国产高清在线| 欧美日韩国产区| 亚洲午夜女主播在线直播| 性xx色xx综合久久久xx| 国产三区精品| 美女黄网久久| 夜夜嗨av一区二区三区中文字幕 | 欧美高清成人| 亚洲无毛电影| 久久躁日日躁aaaaxxxx| 亚洲黄页一区| 国产精品高清在线观看| 午夜视频一区| 欧美激情亚洲综合一区| 亚洲图片欧美日产| 国产一区二区三区在线观看免费视频| 久久精品国产免费| 亚洲日本激情| 久久久91精品国产一区二区三区 | 亚洲欧美bt| 欧美成人黑人xx视频免费观看| 亚洲美女视频在线免费观看| 国产精品v欧美精品v日韩| 欧美一区视频| 亚洲欧洲精品一区二区精品久久久| 亚洲小视频在线观看| 娇妻被交换粗又大又硬视频欧美| 欧美高清视频一区| 欧美一区二区福利在线| 亚洲国产日韩综合一区| 欧美自拍偷拍| 99精品视频免费在线观看| 国产九九精品视频| 欧美精品久久99| 久久精品国产99精品国产亚洲性色| 亚洲国产三级| 男女av一区三区二区色多| 亚洲欧美国产高清va在线播| 亚洲高清123| 国产偷国产偷亚洲高清97cao | 欧美福利视频| 久久精品123| 亚洲一区二区在| 亚洲精品裸体| 欧美国产一区二区三区激情无套| 欧美亚洲系列| 亚洲在线观看免费视频| 日韩午夜免费| **网站欧美大片在线观看| 国产美女精品| 国产精品二区二区三区| 欧美人成在线| 欧美精品一区二区三区蜜臀 | 欧美一级大片在线观看| 一区二区三区欧美成人| 亚洲精品少妇| 亚洲激情成人网| 亚洲高清精品中出| 欧美国产日韩一区二区在线观看 | 一本一本大道香蕉久在线精品| 亚洲成人在线免费| 久久国产精品久久久久久| 一区二区福利| 一区二区冒白浆视频| 亚洲黄色免费网站| 亚洲激情婷婷| 亚洲美女精品久久| 日韩一二在线观看| 一区二区欧美视频| 亚洲一区二区免费视频| 亚洲午夜极品| 亚洲欧美国内爽妇网| 午夜精品免费在线| 欧美在线观看一二区| 欧美一区二区三区在| 久久精品国内一区二区三区| 久久九九久久九九| 另类专区欧美制服同性| 欧美电影免费观看网站| 亚洲国产日韩欧美一区二区三区| 亚洲韩国一区二区三区| 亚洲美女色禁图| 亚洲制服丝袜在线| 久久久91精品| 欧美精品v日韩精品v国产精品| 欧美日韩大片| 国产精品永久免费| 亚洲第一精品电影| 99视频+国产日韩欧美| 亚洲永久网站| 久久久久久91香蕉国产| 欧美二区在线| 国产精品99久久久久久人| 亚洲欧美日韩国产综合| 久久人人爽国产| 欧美精品成人一区二区在线观看| 欧美午夜视频在线观看| 国模精品一区二区三区| 亚洲免费激情| 久久成人这里只有精品| 欧美刺激性大交免费视频| 亚洲乱码精品一二三四区日韩在线 | 亚洲日本乱码在线观看| 亚洲影院免费| 亚洲第一福利视频| 亚洲自拍另类| 欧美精品91| 国内精品久久久久久久97牛牛| 亚洲日韩欧美视频| 久久久精品999| 99re这里只有精品6| 久久男人av资源网站| 欧美色图首页| 亚洲欧洲一区二区在线观看| 午夜精品免费在线| 91久久国产精品91久久性色| 欧美一区二区成人6969| 欧美视频中文字幕在线| 亚洲福利一区| 久久香蕉国产线看观看网| 中文一区二区在线观看| 男女视频一区二区| 国内精品亚洲| 欧美一级免费视频| 99视频有精品| 欧美精品大片| 亚洲靠逼com| 欧美激情一区二区在线 | 亚洲欧美日韩成人高清在线一区|