C++11 std::函数没有名为';目标';
我试图存储唯一函数指针的列表。一个明显的纯指针包装器似乎是 事实证明,C++11 std::函数没有名为';目标';,c++11,gcc,comparison,std-function,C++11,Gcc,Comparison,Std Function,我试图存储唯一函数指针的列表。一个明显的纯指针包装器似乎是 事实证明,std::functions 那么对原始指针进行简单的比较就可以了,对吗?可能吧,但是我得到了以下代码的错误。我的编译器是GCC4.7.2。这是2012年没有实施的吗 std::function<void(bool)> f; void(*p)(bool) = f.target<void(*)(bool)>(); std::函数f; void(*p)(bool)=f.target();
std::function
s
那么对原始指针进行简单的比较就可以了,对吗?可能吧,但是我得到了以下代码的错误。我的编译器是GCC4.7.2。这是2012年没有实施的吗
std::function<void(bool)> f;
void(*p)(bool) = f.target<void(*)(bool)>();
std::函数f;
void(*p)(bool)=f.target();
错误:“class std::function”没有名为“target”的成员
以下是除标题外的相关信息:
#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
\ifdef\uuugxx\urtti
//[3.7.2.5]功能目标访问
/**
*@brief确定此函数对象的目标类型
*包装纸。
*
*@返回目标函数对象的类型标识符,或
*@c typeid(无效)如果@c!(布尔)*这个。
*
*此函数不会引发%异常。
*/
const type_info&target_type()const noexcept;
/**
*@brief访问存储的目标函数对象。
*
*@return返回指向存储的目标函数对象的指针,
*如果@c typeid(Functor).equals(target_type());否则,为空
*指针。
*
*此函数不会引发%异常。
*/
模板_函子*target()无异常;
///@过载
模板常量_函子*target()常量noexcept;
#恩迪夫
我也有这个问题。需要在编译器标志中启用RTTI。
我在编译器标志中使用了
-fno-rtti
。是否使用c++0x
标志的-std=c++11
?您还可以升级编译器和/或使用boost::function
。检查编译器的
头应该足够简单。c++11
,但您的其他注释适用。问题的目的是了解此消息是否意味着.target
尚不受支持,或者我犯了一些愚蠢的错误。我目前正试图从我的
中找出一些东西,但它的位置是2500。那么,您是否激活了RTTI?@n.m。关键是能够从列表中删除这些功能。我正在处理完全相同的问题。