Блог пользователя cacophonix

Автор cacophonix, 13 лет назад, По-английски

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 ?

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
13 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

make it static.

»
13 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится