error C2665 :none of the number1 overloads can convert parameter number2 from type 'type'

J

Joseph Lu

Hi, I have a multithread problem like the following lines, when I compile
this code I caught a "error C2665", the error description is : none of the
number1 overloads can convert parameter number2 from type 'type'

//-----------------------------
UINT ReadDatFile(int i_thread)
{
AfxMessageBox(i_thread);
return 0;
}

// CReadDatFilesView ÏûÏ¢´¦Àí³ÌÐò

void CReadDatFilesView::OnBnClickedReadfile()
{
// TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
UpdateData();
int i_threadnum;
for(i_threadnum=1;i_threadnum<=m_maxthreadnum;i_threadnum++)
{
AfxBeginThread(ReadDatFile(i_threadnum),GetSafeHwnd(),THREAD_PRIORITY_NORMAL);
}
}
//------------------------------
Could anybody tell me why? Thanks in advance!

Joseph
 
B

Bruno van Dooren [MVP VC++]

First of all, when posting questions like this, you should identify the
exact line that triggers the error, and the complete error message.
Otherwise we have to read through all of the code, trying to figure out
which line it might be.
Hi, I have a multithread problem like the following lines, when I compile
this code I caught a "error C2665", the error description is : none of
the number1 overloads can convert parameter number2 from type 'type'

//-----------------------------
UINT ReadDatFile(int i_thread)
{
AfxMessageBox(i_thread);
return 0;
}

This is not the correct function signature for a thread function.
Check MSDN.
// CReadDatFilesView ÏûÏ¢´¦Àí³ÌÐò

void CReadDatFilesView::OnBnClickedReadfile()
{
// TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
UpdateData();
int i_threadnum;
for(i_threadnum=1;i_threadnum<=m_maxthreadnum;i_threadnum++)
{

AfxBeginThread(ReadDatFile(i_threadnum),GetSafeHwnd(),THREAD_PRIORITY_NORMAL);
}
}

You supply the wrong arguments.
The first parameter should be the function pointer only.
You try to supply a function pointer together with the function argument.

If your function has the correct signature, it will receive the 2nd
parameter of AfxBeginThread as a parameter when it is executed.
Read the documentation for AfxBeginThread for more information.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
M

Michael Buechel

//-----------------------------
UINT ReadDatFile(int i_thread)
{
AfxMessageBox(i_thread);
^---- This should be a resource ID or a text


--
Kind regards, Michael Buechel

while(!sleep())
sheeps++;
 
Top