-2

アプリケーションで CreateThread() 関数を使用しようとしましたが、奇妙なエラーが発生しました。

error: invalid conversion from 'DWORD (__ attribute__((__ stdcall__)) *)() {aka long unsigned int (__ attribute__((__ stdcall__)) *)()}' to 'LPTHREAD_START_ROUTINE {aka long unsigned int (__ attribute__((__ stdcall__)) *)(void*)}' [-fpermissive]

In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/windows.h:50:0,

             from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winsock2.h:22,
             from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/ws2tcpip.h:19,
             from include/WinSockClass.hpp:3,
             from C:\Users\Jakub\Desktop\offline\Server\main.cpp:15:
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winbase.h:1423:26: error:   initializing argument 3 of 'void* CreateThread(LPSECURITY_ATTRIBUTES, DWORD, LPTHREAD_START_ROUTINE, PVOID, DWORD, PDWORD)' [-fpermissive]

2 番目は行を示します

WINBASEAPI HANDLE WINAPI CreateThread(LPSECURITY_ATTRIBUTES,DWORD,LPTHREAD_START_ROUTINE,PVOID,DWORD,PDWORD);

winbase.h では、何が起こっているのかわかりません。例では同じことですが、エラーはありません。私は何を間違っていますか?

コード:

#include <iostream>
#include <windows.h>

using namespace std;

int a()
{
   cout << "work";
   return 0;
}
int main(int argc, char **argv)
{
    CreateThread(NULL,0,a,NULL,0,NULL);
    return 0;
}
4

1 に答える 1

0

わかりました、私のせいです、それはうまくいきます

#include <iostream>
#include <windows.h>

using namespace std;

DWORD WINAPI a(LPVOID lpParameter)
{
   cout << "work";
   return 0;
}
int main(int argc, char **argv)
{
    CreateThread(NULL,0,a,NULL,0,NULL);
    return 0;
}
于 2016-02-27T21:23:15.343 に答える