c++ - 未声明的标识符错误消息

标签 c++

我在调用 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

最佳答案

Thread1 在定义之前被使用。

可以将Thread1、Thread2、Thread3函数定义移到main上面

或者您可以在 main 之上声明它。

关于c++ - 未声明的标识符错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26596864/

相关文章:

C++ 我应该使用什么来保存格式化的字符串变量,如 sprintf()?

c++ - 意外分配

c++ - 提高特定任务的 tesseract 性能

c++ - 如何加载 DLL 并访问其方法

c++ - cocos2d-x 如何暂停层的 Action 和调度,然后恢复它们

c++ - 内存映射文件是否为大缓冲区提供了优势?

c++ - 自引用模板

c++ - 如何使用 boost::shared_ptr 构造二叉树

c++ - 在 C++ 套接字连接中发送的奇怪行为

c++ - 如何在 C++ 的另一个模板函数中使用属于模板类的嵌套类型?