?
Solved

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

Posted on 2009-06-29
3
Medium Priority
?
739 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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