模板和提升的编译器错误
Compiler error with templates and boost
我正在创建一个小的线程管理对象,用于在我的程序中以更通用的方式启动线程(目前(。它是基于模板的,我使用提升线程作为底层线程"引擎"。我打算将其用作跨平台包装器,以替换我移植到Linux的一些遗留代码。
我的代码的基本实现如下所示:
using mythread = boost::thread;
class ThreadManager
{
public:
ThreadManager();
~ThreadManager() {}
template<class _Fn, class... _Args>
mythread* CreateThreadPtr(unsigned int Priority, ::std::string& name, unsigned int stackSz, _Fn&& func, _Args&&... args)
{
//boost::thread::attributes attrs;
//attrs.set_stack_size(1024);
//boost::thread t{attrs, thread};
mythread* T = new mythread(func, args...);
void* hndl = (void*)T->native_handle();
if (hndl)
{
#ifdef WIN32
BOOL res = SetThreadPriority(hndl, Priority);
if (!res)
{
//dwError = GetLastError();
}
#else
//TODO
#endif
SetThreadName(T, name);
return T;
}
return NULL;
}
void SetThreadName(THANDLE thread, ::std::string& threadName);
#ifdef WIN32
void SetThreadName(THREAD_ID threadId, ::std::string& threadName);
#endif
#ifdef __linux__
void SetThreadName(void* hThread, ::std::string& threadName);
#endif
THREAD_ID GetThreadId();
};
ThreadManager& Man(void);
将像这样使用:
m_TxRxThread = Man().CreateThreadPtr(Priority, thread_name, 0,ThreadProcTxRx, this);
但是当我构建它时,我收到此错误
/usr/include/boost/bind/bind.hpp:253:35: error: invalid conversion from 'CEth*' to 'long unsigned int' [-fpermissive]
有了-fpermissive
一切似乎都很好,但这对我来说毫无意义,我想知道我在这里做错了什么!
提前感谢!
--编辑--
ThreadProcTxRx
是CEth
对象的方法,其签名为
void CEth::ThreadProcTxRx(ul32 lpParam)
ul32
在哪里typedef unsigned long
...
写下最后这句话,众所周知的灯泡亮了起来......当然,这需要ul32. I was focusing on
ThreadProcTxRx when the error pointed to
这一点。
井。。。感谢禁卫军要求澄清。如果你想把它放在一个答案中,我会为此归功于你。
-允许
将有关不符合代码的某些诊断从错误降级为警告。因此,使用 -fpermissive 将允许编译一些不符合标准的代码。
通过使用-fpermissive
进行编译,您将代码中的一些错误降级为要编译的警告。您应该避免这样做。
您的代码的问题是您正在尝试分配具有CEth*
类型的unsigned long
。如果可能,您需要static_cast
退货到unsigned long
或检查您的退货类型是否正确。
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 编译器错误:destuctor 的更宽松的抛出说明符
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- C++ G++ 编译器 - 错误:隐式声明的定义
- 这个失败的测试是将零添加到空指针未定义的行为、编译器错误还是其他什么?
- 模板模板参数和模板别名:编译器错误?
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- C1001内部编译器错误是由于矢量初始化(如数组)引起的
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 如何在C++中克服此 C4430 编译器错误?
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何在类模板的成员函数中正确调用函数对象?正在生成 Visual Studio 编译器错误 C2440
- C++自定义分配器大小参数作为模板参数会引发编译器错误