-
October 8th, 2017, 01:23 AM
#1
[RESOLVED] Incompatible parameter
Hello, I am using happyhttp to create a class to communicate with a server. I've encountered an error that I simply can't figure out how to fix and still use my class.
It has been 4-5 hours trying to figure this out
Neccesary info about the library are as follows:
happyhttp binds 3 functions
Code:
onBegin
OnData
onComplete
to another function
Taken from their site, these functions are defined as follows:
Code:
typedef void (*ResponseBegin_CB)( const Response* r, void* userdata )
Invoked when all the headers for a response have been received.
The Response object can be queried to determine status and header values.
userdata is the same value that was passed in to Connection::setcallbacks().
typedef void (*ResponseData_CB)( const Response* r, void* userdata, const unsigned char* data, int numbytes )
This callback is invoked to pass out data from the body of the response. It may be called multiple times, or not at all (if there is no body).
typedef void (*ResponseComplete_CB)( const Response* r, void* userdata )
Once a response is completed, this callback is invoked. When the callback returns, the respsonse object will be destroyed.
the function that these are passed to are
Code:
void setcallbacks( ResponseBegin_CB begincb, ResponseData_CB datacb, ResponseComplete_CB completecb, void* userdata )
The example that their site offers is:
Code:
static int count=0;
// invoked when response headers have been received
void OnBegin( const happyhttp::Response* r, void* userdata )
{
printf( "BEGIN (%d %s)\n", r->getstatus(), r->getreason() );
count = 0;
}
// invoked to process response body data (may be called multiple times)
void OnData( const happyhttp::Response* r, void* userdata, const unsigned char* data, int n )
{
fwrite( data,1,n, stdout );
count += n;
}
// invoked when response is complete
void OnComplete( const happyhttp::Response* r, void* userdata )
{
printf( "COMPLETE (%d bytes)\n", count );
}
void TestGET()
{
happyhttp::Connection conn( "www.scumways.com", 80 );
conn.setcallbacks( OnBegin, OnData, OnComplete, 0 );
conn.request( "GET", "/happyhttp/test.php" );
while( conn.outstanding() )
conn.pump();
}
http://prntscr.com/guo9y3 <-hint for the error
http://prntscr.com/guoa3d <-second instance of the error
http://prntscr.com/guoabj <-compiler output
My code is a little large to put here, the paste.ee for is is: https://paste.ee/p/QCqd0
I am not even sure how to name the type of error I'm having past "incompatible Parameter" so i have included 3 screenshots of what my compiler is telling me.
Can somebody please help me identify how to pass my functions to without this error?
-
October 8th, 2017, 04:51 AM
#2
Re: Incompatible parameter
Does the site example compile OK?
See https://docs.microsoft.com/en-us/cpp...er-error-c3867
What version of VS are you using?
This error can also be generated as a result of compiler conformance work that was done for Visual C++ 2005: enhanced pointer-to-member conformance. Code that compiled prior to Visual C++ 2005 will now generate C3867.
When was the happyhttp produced?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 8th, 2017, 04:55 AM
#3
Re: Incompatible parameter
It is impossible to see/undersand anything in the "screenshots" you have attached.
So, please, show us the full error message together with the code snippet(s) related to the error(s).
Victor Nijegorodov
-
October 8th, 2017, 06:16 AM
#4
Re: Incompatible parameter
Ok. I've looked at the code. As Nill_onData() etc are defined within a class, they need to be defined as static because they are passed as function params.
Code:
static void Nill_onData(const happyhttp::Response* r, void* userdata, const unsigned char* data, int n) {}
static void Nill_onRecv(const happyhttp::Response* r, void *userdata) {}
static void Nill_onStop(const happyhttp::Response* r, void *userdata) {}
...
conn.setcallbacks(Nill_onRecv, Nill_onData, Nill_onStop, 0);
This compiles OK with VS 2017. Note that the same is required for onData_recv, onRecv_recv and onStop_recv.
Also note that these functions now cannot directly reference non-static member variables, so if they need to you will need to pass a pointer to the class instance to them.
PS This compiles for VS2017
Code:
class http {
private:
std::string _PubKey;
std::string _PrivKey;
std::string ID;
std::string Debug;
//these are passed to the handler when one of the functional ones aren't needed....
static void Nill_onData(const happyhttp::Response* r, void* userdata, const unsigned char* data, int n) {}
static void Nill_onRecv(const happyhttp::Response* r, void *userdata) {}
static void Nill_onStop(const happyhttp::Response* r, void *userdata) {}
//these are used for the cmdlst: onData checks headers for errors, onRecv is parseable data, onStop is where we resend a packet, but bind nill handles...
static void onData_recv(const happyhttp::Response *r, void *userdata) {}
static void onStop_recv(const happyhttp::Response* r, void *userdata) {
std::string param = "b.php?d=\"";
//param.append(Debug);
param.append("\"");
happyhttp::Connection conn("dev.sitename.ws", 8080);
conn.setcallbacks(Nill_onRecv, Nill_onData, Nill_onStop, 0);
conn.putrequest("POST", (const char*)param.c_str());
conn.putheader("Connection", "close"); //Type of connection
conn.putheader("Content-type", "application/x-www-form-urlencoded"); //More extra header info
conn.putheader("Accept", "text/plain"); //More extra header info
conn.endheaders(); //Finish the creation of the header
while (conn.outstanding()) //While more instructions are waiting
conn.pump(); //Retrieve the information
}
static void onRecv_recv(const happyhttp::Response* r, void* userdata, const unsigned char* data, int n) {
//parser here
}
public:
bool Connect() {
//create the initial header
std::string param = "a.php?";
param.append("UUID = \"");
param.append(ID);
param.append("\"&KEY=\"");
param.append(_PubKey);
param.append("\"");
happyhttp::Connection conn("dev.sitename.ws", 8080);
conn.setcallbacks(onData_recv, onRecv_recv, onStop_recv, 0);
conn.putrequest("POST", (const char*)param.c_str()); //the initial packet is assembled here
conn.putheader("Connection", "close"); //Type of connection
conn.putheader("Content-type", "application/x-www-form-urlencoded"); //More extra header info
conn.putheader("Accept", "text/plain"); //More extra header info
conn.endheaders(); //Finish the creation of the header
while (conn.outstanding()) //While more instructions are waiting
conn.pump(); //Retrieve the information
}
http() {
//unsigned char pk[crypto_box_PUBLICKEYBYTES];
//unsigned char sk[crypto_box_SECRETKEYBYTES];
//crypto_box_keypair(pk, sk);
//_PubKey = reinterpret_cast<const char *> (pk);
//_PrivKey = reinterpret_cast<const char *> (sk);
//ID = GetUUID();
}
};
void Comm() {
http HTTP_LIB;
while (true) {
if (HTTP_LIB.Connect() == false)
break;
}
}
Last edited by 2kaud; October 8th, 2017 at 07:51 AM.
Reason: PS
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 8th, 2017, 11:19 AM
#5
Re: Incompatible parameter
The prntscr links I posted contain the errors, i forgot to remove those attachments before I posted, my apologies..
@2kaud, Your example that you have provided works!
BUT! Optionally, could you please elaborate on "reference to non-static member variables", Maybe provide an example or link me to something I can read on it? I have a gut feeling that will be an issue down the road! And sadly I'm not as versed in classes as I should be!
-
October 8th, 2017, 01:00 PM
#6
Re: Incompatible parameter
could you please elaborate on "reference to non-static member variables"
Code:
//param.append(Debug);
as Debug is a class member variable, it can't be used in onStop_recv() which is now static - that's why I commented out this code line. To pass the name of a class function as a parameter, the class function needs to be defined as static. But a static function can't access any other non-static class variables - only static class variables (which have the same value for all instances of the class). If the static member function(s) require access to non-static member variables then you need to pass a pointer to a class object (this) to the function so that the member variables can be accessed via the passed pointer.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|