Home Ask Login Register

Developers Planet

Your answer is one click away!

Candag February 2016

Compiler error with templates and boost

I'm creating a small thread management object to use to start threads (for now) in a more generic fashion in my programs. It is template based and I am using boost threads as the underlying thread "engine". I intend to use this as a cross platform wrapper to replace some legacy code that I am porting to linux.

The basic implementation of my code looks something like this:

using mythread = boost::thread; 

class 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;
        //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();



            SetThreadName(T, name);

            return T;

        return NULL;

    void SetThreadName(THANDLE thread, ::std::string& threadName);
#ifdef WIN32
    void SetThreadName(THREAD_ID threadId, ::std::string& threadName);
#ifdef __linux__
    void SetThreadName(void* hThread, ::std::string& threadName);

    THREAD_ID GetThreadId();

ThreadManager& Man(void);

Which will be used like this:

m_TxRxThread = Man().CreateThreadPtr(Priority, thread_name, 0,ThreadProcTxRx, this);

But when I build it I get this error

/usr/include/boost/bind/bind.hpp:253:35: error: invalid conversion from 'CEth*' to 'long unsigned int' [-fpermissive]

With -fpermissive


user3639963 February 2016


Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile.

By compiling with -fpermissive you are downgrading some errors with your code to warning to compile. You should avoid doing this.

What's happing with your code is you're trying to assign an unsigned long with a type of CEth*. You will need to static_cast your return to an unsigned long if possible or check your return types are correct.

Post Status

Asked in February 2016
Viewed 1,096 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life