模板好友操作员新明W32
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 是问题所在。
相关文章:
- 使用新行和不使用新行读取文件
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 遇到新行时,有没有办法停止istream_iterator
- Constexpr替代了新的放置方式,可以让内存中的对象保持未初始化状态
- 当一个新对象被分配到它的地址时,对象是否必须被销毁
- 模板元编程:如何将参数包组合成新的参数包
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 如何使用CLion在Mac上创建一个新的.txt文件
- 错误-我无法在VS2019中打开新的Qt项目
- 有没有比在库中添加一个并非由所有派生类实现的新虚拟函数更好的设计实践
- 为什么新的随机库比std::rand()更好
- 在cygwin中测试新的boost安装时出现cpp错误
- C++:继续创建新的变量可以吗
- Qt:当QListView获得新条目时,如何更新QStringList
- 为C++03编译器编写部分unique_ptr,该编译器与较新的编译器在公共代码库上运行
- c++20[[no.unique_address]]中的新功能是什么
- 将指针类分配给新类,C++
- 如何使用新运算符跟踪在循环中创建的 QLabel
- 模板好友操作员新明W32