-1

I got one problem when compiling.

I recive error :

In member function 'void CSConnection::onReadable(const Poco::AutoPtr&)':| CSConnection.cpp|92|error: no matching function for call to 'Poco::ThreadPool::start(QuitHandler*)'| CSConnection.cpp|92|note: candidates are:| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|122|note: void Poco::ThreadPool::start(Poco::Runnable&)| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|122|note: no known conversion for argument 1 from 'QuitHandler*' to 'Poco::Runnable&'| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|127|note: void Poco::ThreadPool::start(Poco::Runnable&, const string&)| c:\mingw\bin..\lib\gcc\mingw32\4.7.2........\include\Poco\ThreadPool.h|127|note: candidate expects 2 arguments, 1 provided| ||=== Build finished: 1 errors, 0 warnings (0 minutes, 1 seconds) ===|

Here is quithandler class :

class QuitHandler : public Runnable
{
    public:
        QuitHandler(){}
        CSConnection * _con;
        void run();
        virtual ~QuitHandler();
    protected:
    private:
        char * _packet;
};

Here error line

QuitHandler * qh;
qh = new QuitHandler();
WorkerThreadPool::getInstance().tp->start(qh);

Thanks!

Kacper Fałat
  • 633
  • 3
  • 9
  • 17

1 Answers1

1

The start method accepts reference, not a pointer: http://pocoproject.org/docs/Poco.ThreadPool.html#11337.

Quick fix would be:

QuitHandler qh;
WorkerThreadPool::getInstance().tp->start(qh);

or

QuitHandler* qh = new QuitHandler();
WorkerThreadPool::getInstance().tp->start(*qh);
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
  • Now i got this error : CSConnection.cpp|90|error: crosses initialization of 'QuitHandler qh'| – Kacper Fałat Aug 21 '13 at 08:28
  • Please post the minimal example demonstrating this error. Or read some explanations of what "crossing initialization" means, and you'll probably find it yourself: http://stackoverflow.com/questions/2392655/what-are-the-signs-of-crosses-initialization. – BartoszKP Aug 21 '13 at 08:49
  • {} in switch fixed it, but application crashes when thread start, run function aren't called. – Kacper Fałat Aug 21 '13 at 09:28
  • Well yes, because after "}" qh gets out of scope and is destroyed. You must redesign the code for "qh" not to be destroyed while the thread is running. I've edited the answer and put an alternative quick fix. – BartoszKP Aug 21 '13 at 09:34
  • No, that's what I'm talking about. That's the problem - "qh" cannot be destroyed while it's needed. And it's needed to be executed in the thread you're creating. You must somehow arrange everything for "qh" to be deleted after the thread finishes. – BartoszKP Aug 21 '13 at 09:41
  • it also crashes with :D QuitHandler* qh = new QuitHandler(); qh->_con = this; WorkerThreadPool::getInstance().tp->start(*qh); – Kacper Fałat Aug 21 '13 at 09:58
  • Then there's something more. Post the minimal example demonstrating the issue, in another question - this one concerns compilation error. – BartoszKP Aug 21 '13 at 10:09