Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

895 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

11 Experts available now in Live!

Get 1:1 Help Now