[英]template friend operator new mingw32
我的理解是new运算符无法进行模板化(使用我使用的参数进行声明时。.(size_t)
下面的代码在mingw32和arduino DUE上可以编译,但是在其他平台(例如linux)上不能编译。
mingw32中是否有错误,还是应该在其他目标上也允许此错误?
class t_other_class
{
public:
// This form of operator new is ***NOT*** allowed to be templated.
void* operator new ( size_t arg1 ) ;
// This form of operator new CAN be templated, and IS.
template<typename TF>
void* operator new ( size_t arg1
, int arg2
) ;
// This form of operator new CAN be templated, but IS NOT.
void* operator new ( size_t arg1
, int arg2
, int arg3
) ;
};
template <typename TCLASS>
class t_class
{
public:
// This form of operator new can NOT be templated, but is ALLOWED in mingw32
template<typename TF> // THIS SHOULD GENERATE AN ERROR
friend
void* t_other_class::operator new ( size_t arg1 ) ;
// Examples of templating..
template<typename TF>
friend /* IS templated in t_other_class*/
void* t_other_class::operator new ( size_t arg1
, int arg2
) ;
template<typename TF>
friend /* IS NOT templated in t_other_class*/
void* operator new ( size_t arg1
, int arg2
, int arg3
) ;
} ;
/*
OK
====
windows
GNU C++ (GCC) version 4.8.2 (i686-w64-mingw32)
DUE
gcc version 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322] (GNU Tools for ARM Embedded Processors)
Error
====
linux
GNU C++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) version 4.8.4 (i686-linux-gnu)
*/
我更新到了最新的Mingw,现在它正确报告了模板声明的滥用(与其他编译器一样)。 看起来是mingw的旧版本是问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.