Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

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
  • Проголосовать: не нравится

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

make it static.

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится