簡體   English   中英

模板朋友運算符new mingw32

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM