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

ACG狂人

其實(shí)我更愛姐汁...

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

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

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

另:附上出錯(cuò)問題的代碼如下
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(); // 用此行便會(huì)出錯(cuò)
    TestUI* ui = TestUI::getSingletonPtr();

    
// 出錯(cuò)開始
    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 釀妹汁 閱讀(5846) 評(píng)論(4)  編輯 收藏 引用 所屬分類: C++

評(píng)論

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

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

# re: boost::bind綁定成員函數(shù)時(shí),第一個(gè)參數(shù)傳遞對(duì)象的特殊情況 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ù)  更多評(píng)論   

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

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

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

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

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧美日韩精品综合在线观看| 欧美在线3区| 免费亚洲视频| 久久精品中文字幕一区| 国产综合色在线| 噜噜噜躁狠狠躁狠狠精品视频| 久久黄色级2电影| 亚洲国产成人91精品 | 国产亚洲精品久久久| 欧美综合国产| 久久欧美中文字幕| 99亚洲一区二区| 亚洲一区二区三区在线观看视频| 国产日本欧美一区二区三区| 美女诱惑黄网站一区| 国产伦精品一区二区三区四区免费| 久久精品成人欧美大片古装| 久久综合色播五月| 亚洲视频一区二区| 欧美在线高清| 一区二区三区久久| 久久av最新网址| 久久成人一区二区| 国产精品久久久久一区二区三区 | 亚洲图片在线观看| 国语精品中文字幕| 亚洲精品乱码久久久久久黑人| 日韩视频免费观看高清完整版| 国产精品高潮呻吟| 欧美a级大片| 国产精品丝袜久久久久久app | 欧美国产一区二区| 国产精品欧美经典| 亚洲一区二区影院| 久久成人国产精品| 国产一区二区三区免费不卡| 欧美一区成人| 亚洲综合欧美| 欧美韩国日本综合| 久久精品国产亚洲一区二区| 国产日韩欧美在线| 亚洲视频观看| 这里只有精品视频| 欧美系列精品| 亚洲欧洲日韩在线| 亚洲高清网站| 欧美精品久久久久a| 麻豆精品视频在线观看视频| 欧美日本韩国一区| 久久天堂国产精品| 亚洲精品在线观看视频| 日韩午夜激情av| 一区二区不卡在线视频 午夜欧美不卡' | 亚洲国产高清aⅴ视频| 国产精品v欧美精品v日本精品动漫| 一区二区三区精密机械公司| 日韩视频一区二区在线观看 | 亚洲视频精选| 久久久久免费观看| 国产精品视频导航| 久久久久久久综合色一本| 欧美在线亚洲在线| 亚洲欧洲日韩综合二区| 久久久国产成人精品| 亚洲高清色综合| 午夜激情久久久| 国产精品一区三区| 美女诱惑黄网站一区| 欧美成人黑人xx视频免费观看| 亚洲美女免费视频| 国产亚洲观看| 欧美视频在线视频| 中日韩视频在线观看| 久久亚洲欧美| 亚洲国产欧美一区二区三区同亚洲 | 亚洲男人影院| 亚洲国产精品999| 国产精品久久久久久久久免费桃花 | 欧美日韩亚洲综合一区| 亚洲精品影院在线观看| 一区二区三区欧美| 一区二区亚洲精品国产| 能在线观看的日韩av| 亚洲经典在线| 久久久久久黄| 亚洲区在线播放| 国产亚洲精品美女| 国产精品久久久久久久第一福利| 男女激情久久| 欧美中文字幕久久| 亚洲制服av| 久久网站热最新地址| 亚洲视频一区| 一区二区三区成人| 日韩视频在线一区二区三区| 国产精品久久91| 欧美激情精品久久久六区热门| 久久精品99久久香蕉国产色戒 | 亚洲精品视频二区| 欧美www在线| 久久久久久网| 久久国产精品一区二区三区| 亚洲欧美日韩国产成人| 亚洲婷婷在线| 亚洲一区日韩在线| 亚洲视频播放| 亚洲影视在线播放| 亚洲线精品一区二区三区八戒| 国产日韩在线一区| 国产精品视频久久一区| 国产精品久久久久久久久久ktv| 欧美日韩高清不卡| 久久久高清一区二区三区| 欧美亚洲综合在线| 欧美在线电影| 久久久久久网| 久久综合导航| 欧美极品一区二区三区| 欧美日韩亚洲一区三区| 欧美视频精品在线观看| 国产精品成人国产乱一区| 欧美特黄a级高清免费大片a级| 国产精品成人播放| 国产视频观看一区| 伊人久久婷婷色综合98网| 国产精品国产三级欧美二区| 国产精品草草| 国产一区二区三区黄视频| 国产综合色一区二区三区| 亚洲福利视频网| 亚洲狼人综合| 亚洲欧美日韩专区| 久久激情视频免费观看| 老色批av在线精品| 亚洲国产欧美久久| 免费在线欧美视频| 亚洲日本中文字幕区| a91a精品视频在线观看| 亚洲狠狠丁香婷婷综合久久久| 91久久久久久久久久久久久| 99在线精品视频在线观看| 午夜在线观看欧美| 亚洲综合第一页| 久久精品首页| 欧美日韩亚洲视频| 国内成人精品一区| 一本色道久久综合| 久久青草福利网站| 日韩一级黄色av| 欧美在线观看网址综合| 欧美激情视频在线播放| 国产精品一区二区久久国产| 亚洲第一在线综合在线| 亚洲国产精品毛片| 亚洲特黄一级片| 久久综合色影院| 99精品免费视频| 久久字幕精品一区| 国产日韩欧美高清免费| 亚洲久久一区| 久久免费国产精品1| a91a精品视频在线观看| 久久午夜av| 国产欧美一区二区三区在线老狼| 亚洲人成啪啪网站| 欧美一区二区精品久久911| 亚洲国产精品成人久久综合一区| 亚洲免费视频成人| 欧美日韩在线播放一区| 伊大人香蕉综合8在线视| 欧美亚洲日本网站| 久久婷婷久久| 亚洲一区二区三区高清不卡| 欧美成人性生活| 国产精品第一区| 亚洲人成欧美中文字幕| 久久综合精品一区| 亚洲欧美另类中文字幕| 欧美婷婷六月丁香综合色| 亚洲三级性片| 性欧美大战久久久久久久久| 亚洲欧洲日韩综合二区| 老牛国产精品一区的观看方式| 国产欧美日韩一区二区三区在线| 亚洲视频在线观看网站| 亚洲国产精品成人| 蜜桃精品久久久久久久免费影院| 国语自产精品视频在线看8查询8| 欧美一区中文字幕| 亚洲一区二区三区视频播放| 欧美日韩综合视频网址| 一区二区三区回区在观看免费视频| 欧美激情精品久久久久久蜜臀 | 欧美在线精品一区| 国产精品无码永久免费888| 亚洲综合另类| 亚洲免费一在线| 国产精品一区二区男女羞羞无遮挡 | 久久精品99国产精品酒店日本| 亚洲午夜精品一区二区|