c++ - Visual Studio 2015 “non-standard syntax; use ' &' to create pointer for member”

标签 c++ multithreading pointers

在 Win32 应用程序中使用 CreateThread() 创建线程时,出现此错误。 在 CreateThread(NULL,0,pSample->Resize(),NULL,0,NULL);它显示函数调用错误。

我确实有几个文件:

main.cpp

WinMain()
 {
   //Create sample
    return Win32Appliaction::Run(&sample);
  }

Win32Application.cpp

int Win32Application::Run(DXSample* pSample)
  {
     //Create Window
     pSample->Init();
     pSample->Render();
     CreateThread(NULL,0,pSample->Resize,NULL,0,NULL);//error occurs
     pSample->Destroy();
  }

DXSample.h

class DXSample
   {
     public:
           virtual void Init() =0; //and rest all functions
   };

HelloTexture.h

 class HelloTexture:public DXSample
   {
       public : 
             virtual void Init();//all other functions similarly
    }

HelloTexture.cpp

void Hellotexture::Init()
 { //code
  } 
 void Hellotexture::Resize()
 {
    //code 
  }

最佳答案

CreateThread 的参数 #2 必须是指向与 ThreadProc 匹配的函数的指针签名。您不能传递 pSample->Resize() 的结果(无效)或指向 Resize 函数本身的指针(因为这是一个非静态类成员函数)。此外,您可能希望使用::std::thread 而不是直接调用 WinApi。

关于c++ - Visual Studio 2015 “non-standard syntax; use ' &' to create pointer for member”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43113015/

相关文章:

c++ - 包装 STL vector 并更改其迭代器的行为

java - 多线程写入文件时的行为

c# - 使用异步 CTP 同时下载 HTML 页面

c++ - 使用线程刷新opencv的问题

c - 二维数组打印错误

c++ - c++17类模板的参数推导中构造函数模板会不会导致歧义

c++ - GCC 接受 `constexpr struct {} s;` 但 Clang 拒绝它。谁是正确的?

c++ - 数独求解矩阵,while语句给出无限循环

c - 设置指向空段错误的指针

pointers - 当我传递一个指针时,我失去了该接口(interface)上所有可用的方法