So, I am fairly new to C++ OOP and am stuck with this (trivial) problem. I have a class definition with a custom comparator like this:
class Solution {
public:
static int pos[30];
static bool cmp(char c1 ,char c2){
return pos[c1 - 'a'] < pos[c2 - 'a'];
}
string customSortString(string S, string T) {
for(int i = 0 ; i < S.length() ; i++){
pos[S[i] - 'a'] = i;
}
sort(T.begin() , T.end() , cmp);
return T;
}
};
I get the error from the compiler
undefined reference to `Solution::pos'
I reckon this has to do with accessing static variable pos
inside non-static method customSortString
but replacing pos
with Solution::pos
still doesn't help.
What am I doing wrong ?