Set with custom function object comparator c++
<p>I have a file, on it's first line is the english alphabet, in a random order, after that, names. I should sort the names according to the alphabet given. My class looks something like this:</p>

<pre><code>class MyCompare(){
   private:
     static map&lt;char, int&gt; order;
   public:
     MyCompare(string alphabet){
        //loop through the string, assign character to it's index in the map
        // order[ alphabet[i] ] = i;
     }
     bool operator()(const string s1, const string s2) {
        //compare every character using compchar, return the result
     }
     bool compchar(const char c1, const char c2){
        return order[c1]&lt;order[c2];
     }        
</code></pre>

<p>}</p>

<p>in the main, I did something like this:</p>

<pre><code>int i=0;

if (myfile.is_open()) {
    while ( myfile.good() ) {
        i++;
        getline (myfile,line);
        if(i ==1){
            MyCompare st(line);
            set&lt;string, MyCompare&gt; words(st);                
        }
        words.insert(line);             
    }
    myfile.close();
}
</code></pre>

<p>of course, this doesn't work, because the set isn't visible outside the if block. I can't come up with anything else, though ... 
Please advise.</p>
