Introduction to C ++ callback function errors

Source: Internet
Author: User

Because c ++ is usually used for writingCode, You may want to write the callback function as a method in the class, But first take a look at the following code:

Class ccallbacktester
{
Public:
Int callback compareints (const byte * velem1, const byte * velem2 );
};
Bubblesort (byte *) array, 5, sizeof (array [0]),
& Ccallbacktester: compareints );

If Microsoft compiler is used, the following compilation error is returned:

Error c2664: 'bubblesort ': cannot convert parameter 4 from

'Int (_ stdcall ccallbacktester: *) (const unsigned char *,

Const unsigned char *) 'to' int (_ stdcall *) (const unsigned char *,

Const unsigned char *) 'There is no context in which this conversion is possible

This is because a non-static member function has an additional parameter: This pointer, which forces you to add static before the member function. Of course, there are several ways to solve this problem, but we will not discuss it any more.
From: http://www.vczx.com/article/show.php? Id = 1007314

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.