std :: function没有成员名为'target' [英] std::function has no member named 'target'

查看:484
本文介绍了std :: function没有成员名为'target'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图存储唯一的函数指针列表。纯粹的指针的一个明显的包装看起来 std :: function

I am trying to store list of unique function pointers. An obvious wrapper to pure pointers seem std::function.

事实证明, std :: function s 无法比较

然后,对原始指针的简单比较应该工作,对吧?也许,但我得到以下错误以下代码。我的编译器是gcc 4.7.2。这是在2012年没有实现的东西吗?

Then a simple comparison of the raw pointers should work, right? Maybe, but I am getting the following error for the following code. My compiler is gcc 4.7.2. Is this something that was not implemented back in 2012?

    std::function<void(bool)> f;
    void(*p)(bool) = f.target<void(*)(bool)>();




错误:'class std :: function'目标'

error: 'class std::function' has no member named 'target'






这里是相关的,除了标题:


Here is the relevant except from the header:

#ifdef __GXX_RTTI
      // [3.7.2.5] function target access
      /**
       *  @brief Determine the type of the target of this function object
       *  wrapper.
       *
       *  @returns the type identifier of the target function object, or
       *  @c typeid(void) if @c !(bool)*this.
       *
       *  This function will not throw an %exception.
       */
      const type_info& target_type() const noexcept;

      /**
       *  @brief Access the stored target function object.
       *
       *  @return Returns a pointer to the stored target function object,
       *  if @c typeid(Functor).equals(target_type()); otherwise, a NULL
       *  pointer.
       *
       * This function will not throw an %exception.
       */
      template<typename _Functor>       _Functor* target() noexcept;

      /// @overload
      template<typename _Functor> const _Functor* target() const noexcept;
#endif


推荐答案

好。 RTTI需要在编译器标志中启用。
我在编译器标志中有 -fno-rtti

I had this problem as well. RTTI needs to be enabled in the compiler flags. I had -fno-rtti in the compiler flags.

这篇关于std :: function没有成员名为'target'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆