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

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>
            国产一区二区高清不卡| 羞羞答答国产精品www一本| 影音先锋久久精品| 亚洲国产高清一区二区三区| 最新亚洲电影| 亚洲一区区二区| 久久九九国产| 亚洲国产免费| 在线看片成人| 亚洲一区一卡| 亚洲欧美卡通另类91av| 欧美中文在线观看| 欧美承认网站| 国产日韩在线一区| 亚洲天堂免费观看| 久久免费视频观看| 一本色道**综合亚洲精品蜜桃冫| 亚洲欧美国产精品桃花| 国产日韩欧美在线| 欧美jizzhd精品欧美巨大免费| 亚洲精品视频在线看| 久久精品在线| 国产精品美女www爽爽爽视频| 在线成人小视频| 亚洲人妖在线| 久久久精品一区| 亚洲乱码视频| 免费欧美视频| 久久成人精品| 国产在线精品一区二区夜色| 亚洲综合欧美日韩| 久久看片网站| 激情久久一区| 欧美freesex8一10精品| 欧美午夜激情小视频| 亚洲毛片在线| 羞羞漫画18久久大片| 欧美日韩a区| 亚洲激情国产| 欧美电影在线免费观看网站| 欧美综合国产精品久久丁香| 日韩一区二区久久| 亚洲精品国产系列| 狠狠久久婷婷| 亚洲第一伊人| 欧美 日韩 国产精品免费观看| 国外成人在线| 亚洲视频每日更新| 国产情侣一区| 久久久久久久综合| 国产精品国产三级国产aⅴ入口 | 国产精品日韩在线观看| 99精品欧美一区二区蜜桃免费| 午夜精品一区二区三区在线播放| 亚洲另类一区二区| 久久亚洲精品一区二区| 亚洲国产另类久久精品| 亚洲欧美精品在线观看| 亚洲午夜高清视频| 亚洲欧美国产精品va在线观看| 亚洲免费成人| 欧美久久久久久蜜桃| 日韩视频在线一区| 米奇777超碰欧美日韩亚洲| 99ri日韩精品视频| 免费不卡欧美自拍视频| 久久综合综合久久综合| 欧美sm视频| 91久久中文字幕| 国产精品久久国产精品99gif| 亚洲人成高清| 亚洲视频大全| 国产精品久久久久91| 一区二区三区国产盗摄| 亚洲一区二区三区四区五区黄| 欧美伦理91i| 日韩视频在线观看一区二区| 国产一区二区日韩| 香港久久久电影| 久久亚洲精品欧美| 欧美性大战久久久久久久| 99精品欧美一区二区三区综合在线| 国产精品日韩欧美一区二区三区| 99亚洲一区二区| 欧美有码视频| 欧美日韩高清免费| 亚洲天堂视频在线观看| 亚洲黄色大片| 欧美精品一区二区三区四区| 亚洲精品日韩综合观看成人91| 99国内精品久久| 国产人成精品一区二区三| 欧美在线1区| 亚洲国产精品va在线观看黑人| 亚洲精品乱码久久久久| 久久久精彩视频| 亚洲第一二三四五区| 一区二区三区欧美在线| 久久综合一区二区三区| 久久精品国产99| 欧美丝袜一区二区| 久久国产精品毛片| 激情久久久久久久久久久久久久久久| 久久久蜜臀国产一区二区| 亚洲国产欧美一区| 午夜精品www| 欧美日韩精品免费 | 免费一级欧美在线大片| 亚洲肉体裸体xxxx137| 国产精品久久久久aaaa| 久久精品视频99| 亚洲九九精品| 久久亚洲风情| 亚洲欧美色一区| 亚洲黄色成人网| 欧美天堂亚洲电影院在线播放| 久久国产精品黑丝| 日韩视频欧美视频| 亚洲成色777777女色窝| 伊甸园精品99久久久久久| 欧美日韩亚洲天堂| 亚洲网在线观看| 亚洲国产免费| 狼人社综合社区| 亚洲欧美视频在线观看| 亚洲看片一区| 最新精品在线| 亚洲承认在线| 黑人巨大精品欧美黑白配亚洲| 欧美日韩中文| 欧美女激情福利| 免费成人av| 久久久久久一区二区三区| 亚洲性夜色噜噜噜7777| 日韩网站免费观看| 亚洲黄色高清| 欧美黑人国产人伦爽爽爽| 亚洲人成在线观看一区二区| 国产一区二区三区丝袜| 国产欧美va欧美va香蕉在| 欧美激情中文不卡| 亚洲无吗在线| 日韩视频在线播放| 亚洲精品网址在线观看| 亚洲高清资源综合久久精品| 麻豆9191精品国产| 久久影院亚洲| 免费短视频成人日韩| 久久亚洲不卡| 欧美 日韩 国产一区二区在线视频 | 国产精品中文字幕在线观看| 艳女tv在线观看国产一区| 亚洲肉体裸体xxxx137| 亚洲国产另类久久精品| 亚洲精选中文字幕| 一区二区日本视频| 亚洲视频欧洲视频| 午夜精品久久久久久久99水蜜桃| 欧美国产日韩精品| 亚洲电影欧美电影有声小说| 亚洲国内高清视频| 亚洲伦理自拍| 亚洲欧美偷拍卡通变态| 午夜视黄欧洲亚洲| 久久永久免费| 欧美日韩激情网| 国产精品视频观看| 韩国av一区二区| 亚洲精品视频在线看| 亚洲图色在线| 久久久欧美精品sm网站| 欧美激情中文字幕乱码免费| 亚洲国产精品久久精品怡红院| 亚洲美女中文字幕| 亚洲自拍偷拍麻豆| 久久亚洲春色中文字幕| 欧美精品国产一区二区| 国产精品扒开腿做爽爽爽软件| 国产人成精品一区二区三| 亚洲国产精品福利| 亚洲欧美日韩在线播放| 一区二区av| 激情成人亚洲| 亚洲免费观看在线视频| 小嫩嫩精品导航| 欧美福利网址| 亚洲综合视频1区| 牛牛国产精品| 国产免费亚洲高清| 亚洲破处大片| 久久国产精品久久久久久| 亚洲九九九在线观看| 欧美在线播放一区二区| 欧美成人日本| 午夜精品视频网站| 欧美日韩国产影片| 亚洲高清不卡| 玖玖视频精品| 亚洲欧美综合| 国产精品国产自产拍高清av王其|