簡體   English   中英

指向模板參數的類成員函數的指針

[英]Pointer to class member function of template parameter

嗨我在XCode,gcc(Apple LLVM編譯器3.0)中編譯我的類有問題我寫了類ContextSchedule它意味着封裝其他類成員函數列表的類,並且在MSVC ++ 2005下編譯它沒有問題。

template<class T>
class C_ContextScheduler
{
public:
    typedef void (T::*T_EventFunc)();
    typedef std::map<u64, T_EventFunc>  T_EventMap;

public:
    //@ c-tor
    C_ContextScheduler(T & context) : m_Context(context), m_currentTick(0) {};

    //@ Schedule
    //@ funcPtr - pointer to function of class T
    //@ dellayTime in milliseconds - after dellayTime from now will be funcPtr called
    void    Schedule(T_EventFunc funcPtr, u32 dellayTime)
    {
        u64 callingTime = m_currentTick + dellayTime;
        std::pair<int, bool> res = m_eventMap.insert(T_EventMap::value_type(callingTime, funcPtr));
        SC_ASSERT(res.second);
    }  ...

有任何想法嗎? 想要保存這個解決方案的模板方式,thnx。

當編譯器編譯此模板時, T尚不知道。 因此, T_EventFuncT_EventMap的確切類型也是未知的,編譯器不知道T_EventMap::value_type最終會成為一個類型。 要明確這一點,請使用typename關鍵字:

... = m_eventMap.insert(typename T_EventMap::value_type(callingTime, funcPtr));

既然你沒有提供你得到的錯誤,我們只能猜測。 我的猜測是你的插入調用的結果是不正確的。

根據這個引用std::map::insert的返回值是std::pair<iterator, bool> 你確定迭代器是一個int嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM