thread_local c 11,VS2015中的错误C2492
thread_local C++11, Error C2492 in VS2015
我有这样的类:
在CustomAllocator.h文件中:
namespace MemoryMgmt
{
class PoolMemory
{
....
}
}
class CustomAllocator
{
public:
void * operator new(size_t i_size);
void operator delete(void*, void*);
virtual ~CustomAllocator(){};
#pragma warning(suppress: 4251)
static thread_local MemoryMgmt::PoolMemory memory_manager_current;
};
inline void * CustomAllocator::operator new(size_t i_size)
{
return memory_manager_current.AllocateChars(i_size);
}
inline void CustomAllocator::operator delete(void * , void*)
{
//Should not be used
ASSERT(!"Placement delete should not be used for memory objects");
}
在customallocator.cpp文件中:
#include <CustomAllocator.h>
thread_local MemoryMgmt::PoolMemory CustomAllocator::memory_manager_current;
我在许多不同的库中使用了自定义辅助器类。我会收到以下错误(许多错误与:
相同)error C2492: 'public: static MemoryMgmt::PoolMemory CustomAllocator::memory_manager_current': data with thread storage duration may not have dll interface (compiling source file D:*******.cpp)
我使用Visual Studio 2015,我想它在此版本中得到了完全支持。
当您一起使用__declspec(dllexport)
和__declspec(thread)
时,会发生此错误。在您的情况下,memory_manager_current
是static
类成员用作线程本地存储。但是,我强烈怀疑该类可能已经用属性__declspec(dllexport)
声明(尽管在您的帖子中没有看到)。
您可以安全地将memory_manager_current
移出课堂,并将其作为class CustomAllocator
实现文件中的全局变量。
希望这会有所帮助。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- thread_local c 11,VS2015中的错误C2492