我的理解是operator 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)
*/
答案 0 :(得分:0)
我更新到最新的Mingw,它现在正确地报告了模板声明的滥用(按照其他编译器)。看起来老版本的mingw就是问题。