Solved

How to declare my TList->sort function in (Class)header?

Posted on 2009-06-29
3
717 Views
Last Modified: 2013-11-17
I'm using Borland C++ Builder and I've written my own sort function to sort a TList.

The code is:

int __fastcall my_sort_function(void *Item1, void *Item2){

      ... compare something
      return(result);
}

Im using it to do: MySortList->Sort(my_sort_function);

That works well!

The Question is:
How to declare
int __fastcall my_sort_function(void *Item1, void *Item2)
in the header file to make it a class member?

Reason: I'd like to give "my_sort_function" access to some class members.

This may be a stupid question? But I'm very new to C++ and learn the basic concepts now. Can anyone help me?


Thanks in advance!
0
Comment
Question by:hasnpapa
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 24737200
Hi hasnpapa,

you'll have to implement your function as a 'static' method. Then the function can even access i.e. protected members. In the function you have to cast the void-pointers to pointers of the class.


Hope that helps,

ZOPPO
0
 

Author Closing Comment

by:hasnpapa
ID: 31597974
Thnks a lot - that helps me out! :-)
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 24743565
You're welcome ...

have a nice day,

best regards,

ZOPPO
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question