Job:
my class "network" contains a vector "taus". I wish "network" to be able to find the indexes of the n smallest elements.
My first idea was along the lines (this is mostly meant as pseudo-code):
#include<algorithm>
#include<vector>
#include<cstdlib>
class network
{
vector <double> taus;
vector <int> nsmallest;
vector <int> Indexes;
network(){
Indexes.resize(100);
taus.resize(100);
for(int i=0;i<100;i++){Indexes[i]=i; taus[i]=rand;}
}
bool tauComp(int i,int j) {return (taus[i]>taus[j]);};
void findSmallest(){
partial_sort_copy(Indexes.begin(), Indexes.end(), nIndexes.begin(), nIndexes.end(), &((*this).tauComp)); }
};
however, "ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say ‘&network::tauComp’" - which is what g++ responds.
So, since I am only bothering with one network at a time, I could make both tauComp and taus static, which should allow me to pass a pointer to it. However, that is pretty unsatisfactory, and I'd rather not have to worry about that whenever I fool around with several networks (which I guess I'm bound to be sooner or later).
I wouldn't mind making just tauComp static, but then I'd need some way of passing a pointer to tauComp to tell it which taus I want it to use when comparing (and I don't see how I can include that in the code above).
Then of course there's also the option of abandong partial_sort_copy and just do my own search algorithm, but that feels like giving up (and it's potentially a hazzle).
any suggestions? if there's an alternative to partial_sort_copy which could take taus directly, that would work as well...
I hope the above is clear =)