std :: function没有名为'target'的成员

时间:2014-11-13 11:13:32

标签: c++11 gcc comparison std-function

我正在尝试存储唯一函数指针的列表。纯指针的明显包装似乎是std::function

事实证明,std::function s cannot be compared

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

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

错误:&#39; class std :: function&#39;没有名为&#39; target&#39;

的成员

以下是除标题之外的相关内容:

#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

1 个答案:

答案 0 :(得分:1)

我也有这个问题。需要在编译器标志中启用RTTI。 我在编译器标志中有procedure TForm1.Button1Click(Sender: TObject); var Q: TSQLQuery; d: string; begin //Q := TSQLQuery.Create(nil); with OracleConnection1 do begin Connected := true; SQLTransaction1.Active:= True; DataSource1.Enabled:=true; DataSource1.DataSet := Q; end; if OracleConnection1.Connected then Q.SQL.Text := 'SELECT description FROM part where part= "00000" '; Q.Active:=true; Q.ExecSQL; d := datasource1.DataSet; //DBText1.ExecuteAction(); dbedit1.Text:= q.DataSource.DataSet.Fields.; Edit1.Text:= Q.SQL.Text; showmessage('CONNECTED'); sql.Active:=true; end;