不兼容的参数错误消息 [英] incompatible parameter error message

查看:198
本文介绍了不兼容的参数错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是Cthread.h文件:



Following is the Cthread.h file:

#ifndef Cthread_H_
#define Cthread_H_

#include <windows.h>
#include <process.h>
#include <time.h>
#include <algorithm>

class Cthread
{
	
	//This is the handle to our thread system give us when
	//Thread is created.
	HANDLE MySendThread;
	DWORD MySendThreadId;

	HANDLE MyReceiveThread;


public:
	/***local Thread***/
	//automatically set the default values of running, end, tid and handle variables
	Cthread();

        /*Receive Thread:*/
	void ReceiveThread(void* data);
	
	/*Send Thread:*/
	DWORD WINAPI SendThread(LPVOID lpParam); 

};

#endif
/*Cthread_H*/







以下是Cthread.cpp文件:






The following is the Cthread.cpp file:

#include "Cthread.h"

/******************Threads***************************/

Cthread::Cthread()
{
	//This means thread is not running
	Running = false;
	//Our signal for stopping thread, in this case not.
	End = false;

	//Set default values for identifier and handle
	MySendThread = 0;
	MyReceiveThread = 0;
}

/*Receive Thread initiator*/
void Cthread::ReceiveThread(void* data)
{

	//VNSelement = VNS(EDIP_UDP_PORT_NO);
}

/*Send Thread initiator*/
DWORD WINAPI Cthread::SendThread(LPVOID lpParam)
{
	int result;
    //char * mytxdata = "Hello";
    int dataSize;
    char * mytxdata;
   
	char sendArray[1500] = { 0x01, 0x02, 0x03 }; 

    //mytxdata = reinterpret_cast<char*>(&test);
    //dataSize = sizeof(test);

    while (1)
    {

        //result = UdpServer::send ( socketno, mytxdata, dataSize, VNS_UDP_IP_NO, EDIP_UDP_PORT_NO );

        if ( result == 0 )
        {
            //cout << "Send!\n";
        }
        
    }
}


/*Starts Thread*/
void Cthread::start()
{
	//Pass static_run function and whole object as parameter.
	//Get handle to our thread and identifier (tid)
	MySendThread = CreateThread(NULL,0, SendThread, 0, 0, &MySendThreadId );
	MyReceiveThread = (HANDLE)_beginthread( &ReceiveThread, 0, 0);

	//VNSelement.VNS_Initiate_Decode();
}





问题在于:当我运行上面的代码程序时,它会给我以下错误:





IntelliSense:类型为void(Cthread :: *)(void * data)的参数与void(__ cdecl *)类型的参数不兼容(void *)



IntelliSense:DWORD(__stdcall Cthread :: *)(LPVOID lpParam)类型的参数与LPTHREAD_START_ROUTINE类型的参数不兼容br $>


错误C3867:'Cthread :: SendThread':函数调用缺少参数列表;使用'& Cthread :: SendThread'创建指向成员的指针



错误C2276:'&':对绑定成员函数表达式的非法操作





我现在有点困惑,任何帮助都表示赞赏。谢谢!



The problem is this: when I run the code program above, it gives me the following errors:


IntelliSense: argument of type "void (Cthread::*)(void *data)" is incompatible with parameter of type "void (__cdecl *)(void *)"

IntelliSense: argument of type "DWORD (__stdcall Cthread::*)(LPVOID lpParam)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"

error C3867: 'Cthread::SendThread': function call missing argument list; use '&Cthread::SendThread' to create a pointer to member

error C2276: '&' : illegal operation on bound member function expression


I'm kind of confused for the moment, any help is appreciated. thanks!

推荐答案

通过 start_address 参数传递的线程函数必须是静态的。因此,在头文件中将它们定义为 static

The thread functions passed via the start_address parameters must be static. So define them as static in the header file:
/*Receive Thread:*/
static void ReceiveThread(void* data);
	
/*Send Thread:*/
static DWORD WINAPI SendThread(LPVOID lpParam);





C3867的错误消息告诉您该怎么做。



错误C2276通过传递函数以C3867消息所指示的相同样式来解决(& Cthread :: ReceiveThread )。


正如 Jochen Arndt 已经说明的那样,你的线程函数不能是你的类的实例方法。如果您需要访问类实例,请使用本页底部显示的技巧:回调,线程和MFC [ ^ ](该示例涉及MFC,但该技术更常见)。
As Jochen Arndt already stated, your thread function cannot be an instance method of your class. If you need access to a class instance, use the technique shown at the bottom of this page: "Callbacks, Threads, and MFC"[^] (the example refers to MFC, but the technique is more general).


对于该用途,函数签名必须完全匹配。现在你的funcs是类中的成员函数。它们必须在类或全局函数中是静态的。您可以在此类函数中使用全局对象,或者输入参数与主对象或数据相关。在这里你可以找到som 示例代码
for that use the functions signatures must match exactly. Now your funcs are member funcs in the class. They must be static in the class or global funcs. You can use global objects in such functions or the input parameter is poiting to the main object or data. Here you will find som example code.


这篇关于不兼容的参数错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆