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

ACG狂人

其實我更愛姐汁...

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

boost::bind(&memberfunction, obj, _1, _2........)類似這樣的用法,我們叫做成員函數(shù)綁定,boost庫的文檔中說的很清楚,第一個參數(shù)可以是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);

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

另:附上出錯問題的代碼如下
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
<<"鍵盤響應(yīng)"<<std::endl;
    }


    
void processMouse(EventArgs& args){
        std::cout
<<"鼠標(biāo)響應(yīng)"<<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 釀妹汁 閱讀(5832) 評論(4)  編輯 收藏 引用 所屬分類: C++

評論

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

為啥不用boost::mem_fn ?  回復(fù)  更多評論   

# re: boost::bind綁定成員函數(shù)時,第一個參數(shù)傳遞對象的特殊情況 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)


  回復(fù)  更多評論   

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

文檔上有說明  回復(fù)  更多評論   

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

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

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲男人的天堂在线| 国产视频精品免费播放| 亚洲盗摄视频| 香蕉成人伊视频在线观看| 在线视频亚洲| 亚洲免费视频中文字幕| 亚洲女女女同性video| 亚洲视频在线视频| 亚洲女性喷水在线观看一区| 午夜精品国产更新| 欧美一区三区三区高中清蜜桃| 亚洲一区二区三区在线观看视频| 亚洲无线观看| 久久大综合网| 欧美国产日韩精品免费观看| 亚洲国产小视频在线观看| 亚洲精品久久视频| 亚洲深夜福利在线| 欧美一区视频| 男女精品网站| 欧美午夜免费影院| 韩国视频理论视频久久| 亚洲国产一二三| 亚洲一区国产视频| 久久婷婷丁香| 亚洲三级免费| 午夜精品成人在线| 久久综合精品一区| 国产精品www994| 伊人一区二区三区久久精品| 一卡二卡3卡四卡高清精品视频| 久久精品人人| 亚洲美女尤物影院| 欧美专区福利在线| 欧美激情麻豆| 国产午夜亚洲精品羞羞网站| 亚洲欧洲日本国产| 久久狠狠婷婷| 亚洲精品久久久蜜桃| 久久成人精品一区二区三区| 欧美精品一区二| 激情一区二区三区| 亚洲欧美激情四射在线日 | 亚洲国产精品一区二区www在线| 中国亚洲黄色| 欧美1区免费| 欧美在线电影| 国产精品自拍网站| 一本到高清视频免费精品| 久久一区亚洲| 欧美在线资源| 国产亚洲女人久久久久毛片| 亚洲视频在线观看三级| 亚洲国产精品成人综合色在线婷婷| 亚洲欧美激情在线视频| 欧美午夜不卡| 亚洲一区免费网站| 亚洲国产精品一区| 狂野欧美激情性xxxx欧美| 国产网站欧美日韩免费精品在线观看 | 欧美大尺度在线| 欧美一区二区大片| 国产精品综合久久久| 亚洲在线1234| 夜夜嗨av一区二区三区四区| 欧美高清在线一区二区| 亚洲精品在线二区| 欧美激情欧美激情在线五月| 噜噜噜躁狠狠躁狠狠精品视频| 黄色国产精品| 欧美大胆人体视频| 欧美不卡高清| av成人天堂| 亚洲一级片在线看| 国产伦精品一区二区三区照片91 | 亚洲欧美在线一区| 亚洲婷婷综合久久一本伊一区| 国产精品国产三级国产aⅴ无密码| 国产一区二区三区黄视频| 欧美激情精品久久久六区热门 | 亚洲免费高清| av成人免费| 国产美女精品在线| 老司机精品导航| 老司机免费视频一区二区三区| 在线观看国产一区二区| 欧美www视频在线观看| 欧美黄色大片网站| 亚洲无线一线二线三线区别av| 夜夜夜精品看看| 中文国产成人精品久久一| 亚洲性感激情| 在线欧美日韩精品| 蜜臀va亚洲va欧美va天堂 | 99国产精品国产精品久久| 亚洲第一伊人| 久久人91精品久久久久久不卡| 亚洲国产精品va在线看黑人动漫| 亚洲成人在线网| 欧美日韩不卡| 性做久久久久久久久| 欧美一区二区三区在线免费观看| 国产一区二区三区在线观看网站 | 亚洲欧美综合精品久久成人| 国产一区二区在线观看免费| 麻豆91精品| 欧美日韩国产精品一区| 亚洲一区二区在线观看视频| 亚洲午夜电影在线观看| 国产视频一区在线观看一区免费| 欧美α欧美αv大片| 欧美日韩高清在线| 欧美在线观看网址综合| 玖玖精品视频| 亚洲综合好骚| 久久爱www| 一区二区日韩免费看| 在线视频日本亚洲性| 狠狠色综合网| 日韩亚洲欧美高清| 国产一区视频网站| 亚洲电影免费观看高清完整版| 欧美精品系列| 久久精品91久久久久久再现| 欧美激情一区二区三区在线视频观看| 亚洲欧美国产不卡| 久热精品视频在线观看一区| 亚洲国产第一| 久久亚洲私人国产精品va媚药| 欧美成人乱码一区二区三区| 91久久国产综合久久蜜月精品| 国产精品久久二区二区| 免费观看30秒视频久久| 欧美视频在线观看一区二区| 美女主播精品视频一二三四| 嫩草国产精品入口| 欧美激情一区二区久久久| 国产视频一区三区| 99热免费精品| 最新国产乱人伦偷精品免费网站| 亚洲欧美精品伊人久久| 一本色道精品久久一区二区三区| 亚洲一区在线观看视频| 亚洲综合三区| 欧美黄色影院| 欧美成人久久| 伊人久久大香线蕉av超碰演员| 亚洲一区二区三区精品在线| 一本大道久久精品懂色aⅴ| 欧美亚洲日本国产| 免费观看亚洲视频大全| 国产一区二区三区在线免费观看 | 欧美四级在线观看| 欧美国产另类| 91久久黄色| 久久一区二区三区国产精品| 久久午夜精品| 含羞草久久爱69一区| 欧美在线免费视频| 久久久.com| 国产综合精品| 久久久久国产成人精品亚洲午夜| 久久久久久久久久码影片| 亚洲国产成人午夜在线一区| 久久午夜精品| 亚洲国产成人不卡| 亚洲精品乱码久久久久久按摩观| 老色鬼久久亚洲一区二区| 欧美暴力喷水在线| 国产午夜久久久久| 欧美成人蜜桃| 欧美激情第3页| 国内成人精品2018免费看| 久久国产精品72免费观看| 六月婷婷久久| av成人黄色| 国产精品羞羞答答| 久久精品99国产精品日本| 欧美一区二区三区免费观看视频| 国产精品免费视频xxxx| 亚洲摸下面视频| 久久―日本道色综合久久| 亚洲第一精品久久忘忧草社区| 美女主播视频一区| 亚洲精品美女91| 久久视频精品在线| 一本色道久久综合| 欧美有码在线视频| 亚洲国产精品久久久久婷婷884| 欧美一区影院| 欧美激情四色| 午夜精品久久久久久久99水蜜桃 | 欧美高清视频一二三区| 亚洲精品一区二区三区99| 国产精品九九久久久久久久| 亚洲三级电影全部在线观看高清| 久久久久久久综合日本| 亚洲欧洲一区二区三区| 国产精品毛片大码女人| 麻豆精品视频在线观看|