Please read the new rule regarding the restriction on the use of AI tools. ×

cacophonix's blog

By cacophonix, 11 years ago, In English

EDITED:

I want to use a custom compare function written inside a class like this code.

class cl{ 
	public: 
	
	string st; 
	int *pos;
	
	cl(string s){
		st=s; 
		pos=new int[s.size()];
		for (int i = 0; i < (int)s.size(); i++){
			pos[i]=i;
		}
		
	} 
	
	
	static int compare(int c1,int c2 ){
		 return st[c1]<st[c2]; 
	} 
	
	
	void function_using_custom_compare_function(){
		 sort(pos,pos+st.size(),compare); 
	} 
};

but i cant compile this code.

how to use the compare function inside a class ?

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +3 Vote: I do not like it

make it static.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thanks for your reply. I have edited the code which I actually need. now making the compare function static does not solve the problem.

»
11 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it