调用CreateThread
函数时收到错误消息。
#include "stdafx.h"
#include "Functions.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[]) {
DWORD TidA, TidB, TidC;
HANDLE task1, task2, task3;
task1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Thread1, NULL, 0, &TidA);
task2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Thread2, NULL, 0, &TidB);
task3 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Thread3, NULL, 0, &TidC);
SetThreadPriority(task1, THREAD_PRIORITY_HIGHEST);
SetThreadPriority(task2, THREAD_PRIORITY_NORMAL);
SetThreadPriority(task3, THREAD_PRIORITY_LOWEST);
CloseHandle(task1);
CloseHandle(task2);
CloseHandle(task3);
}
void Thread1()
{
printf("Task#2 >>> started\n");
int *firstFunc = (new Functions())->firstFunc(Data::vectorInitialize(), Data::matrixInitialize(), Data::matrixInitialize());
Sleep(3000);
Data::vectorOutput(firstFunc);
printf("\nTask#2 >>> finished\n");
}
void Thread2()
{
printf("Task#1 >>> started\n");
int **secondFunc = (new Functions())->secondFunc(Data::matrixInitialize(), Data::matrixInitialize(), Data::matrixInitialize(), Data::matrixInitialize());
Sleep(2000);
Data::matrixOutput(secondFunc);
printf("\nTask#1 >>> finished\n");
}
void Thread3()
{
printf("Task#3 >>> started\n");
int *thirdFunc = (new Functions())->thirdFunction(Data::matrixInitialize(), Data::matrixInitialize(), Data::vectorInitialize());
Sleep(1000);
Data::vectorOutput(thirdFunc);
printf("\nTask#3 >>> finished\n");
}
以下是错误消息:
error C2065: Thread1: undeclared identifier
error C2065: Thread2: undeclared identifier
error C2065: Thread3: undeclared identifier
答案 0 :(得分:3)
Thread1在定义之前使用。
您可以将Thread1,Thread2,Thread3函数定义移动到上面的主
或者您可以将其声明为主要内容。
答案 1 :(得分:2)
您应该在_tmain
之前声明函数:
void Thread1();
void Thread2();
void Thread3();