Solved

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

Posted on 2009-06-29
3
701 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 30

Accepted Solution

by:
Zoppo earned 500 total points
Comment Utility
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
Comment Utility
Thnks a lot - that helps me out! :-)
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
You're welcome ...

have a nice day,

best regards,

ZOPPO
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now